13 days ago
I do have a monorepo
pacakges:
backend (node)
comomn (ts)
frontend (react)
My project frontend crashs all the time on every build.
Idk what is missing, i did tryied several different settings. I dont know where setup where my dist folder is, maybe is this the issue maybe not
Application failed to respondThis error appears to be caused by the application.
If this is your project, check out your deploy logs to see what went wrong. Refer to ourdocs on Fixing Common Errors for help, or reach out over our Help Station.
If you are a visitor, please contact the application owner or try again later.
Request ID:
1ddbqeKJT5aQ9NCBAax-fw
Pinned Solution
12 days ago
In a pnpm workspace, Firstly, you need to set the Root Directory to / or leave it empty in your service settings. Then you should use custom build/start commands.
ExampleFrontend Service:
Build Command:pnpm build --filter=frontend where "frontend" is the name specified in frontend/package.json file.
Start Command: pnpm start --filter=frontend
Do the same for the backend service.
Note that you should have build/start scripts in backend/package.json and frontend/package.json .
I host a pnpm monorepo here on Railway, and it works with no problems. Hope this helps.
12 Replies
Status changed to Awaiting Railway Response Railway • 13 days ago
13 days ago
Hey,
Do you have any errors or exit codes from the crashes?
Have you tried adding each individually as a separate services?
13 days ago
Request ID:
mm0fViToTt2Ar9VCO8poTA
I dont get why the log is showning the backend error
Node.js v22.22.0
node:internal/modules/cjs/loader:1386
throw err;
^
Error: Cannot find module '/app/packages/backend/dist/main'
at Function._resolveFilename (node:internal/modules/cjs/loader:1383:15)
at defaultResolveImpl (node:internal/modules/cjs/loader:1025:19)
at resolveForCJSWithHooks (node:internal/modules/cjs/loader:1030:22)
at Function._load (node:internal/modules/cjs/loader:1192:37)
at TracingChannel.traceSync (node:diagnostics_channel:328:14)
at wrapModuleLoad (node:internal/modules/cjs/loader:237:24)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:171:5)
at node:internal/main/run_main_module:36:49 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
/app/packages/backend:
ERR_PNPM_RECURSIVE_RUN_FIRST_FAIL @harasfacil/backend@1.0.0 start:prod: NODE_ENV=production node dist/main
xmrafonso
Hey,Do you have any errors or exit codes from the crashes?Have you tried adding each individually as a separate services?
13 days ago
At this moment they are separated yes
souzaricardo
Request ID:mm0fViToTt2Ar9VCO8poTAI dont get why the log is showning the backend errorNode.js v22.22.0node:internal/modules/cjs/loader:1386throw err;^Error: Cannot find module '/app/packages/backend/dist/main'at Function._resolveFilename (node:internal/modules/cjs/loader:1383:15)at defaultResolveImpl (node:internal/modules/cjs/loader:1025:19)at resolveForCJSWithHooks (node:internal/modules/cjs/loader:1030:22)at Function._load (node:internal/modules/cjs/loader:1192:37)at TracingChannel.traceSync (node:diagnostics_channel:328:14)at wrapModuleLoad (node:internal/modules/cjs/loader:237:24)at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:171:5)at node:internal/main/run_main_module:36:49 {code: 'MODULE_NOT_FOUND',requireStack: []}/app/packages/backend:ERR_PNPM_RECURSIVE_RUN_FIRST_FAIL @harasfacil/backend@1.0.0 start:prod: NODE_ENV=production node dist/main
13 days ago
Did you double check your starting command? Is it pointing to the correct place?
Make sure it's building and that dist/ is created.
xmrafonso
Did you double check your starting command? Is it pointing to the correct place?Make sure it's building and that dist/ is created.
13 days ago
That is the point
I dont find any doc about it
Why do i need a start command for a react frontend once build its a static hosting
Thanks
souzaricardo
That is the pointI dont find any doc about itWhy do i need a start command for a react frontend once build its a static hostingThanks
13 days ago
Well the problem is that railway is detecting the backend and thinks it is a node/backend service.
Railway uses containers, it does not serve static files.
An option would be to use Bun/Vite with react.
xmrafonso
Well the problem is that railway is detecting the backend and thinks it is a node/backend service.Railway uses containers, it does not serve static files.An option would be to use Bun/Vite with react.
13 days ago
Im using vite on my fe projet
Well, i will try this since ita my first mononrepo deploy
My other fe project works correctly without these hacks but its a dedicated repo for each be and fe
12 days ago
.
souzaricardo
Im using vite on my fe projetWell, i will try this since ita my first mononrepo deployMy other fe project works correctly without these hacks but its a dedicated repo for each be and fe
12 days ago
Well, I am not sure monorepos work in railway, at least you can't run everything in a single service.
So, you'd have to have 3 separate services, each with a modified start/build command for each specific thing.
12 days ago
In a pnpm workspace, Firstly, you need to set the Root Directory to / or leave it empty in your service settings. Then you should use custom build/start commands.
ExampleFrontend Service:
Build Command:pnpm build --filter=frontend where "frontend" is the name specified in frontend/package.json file.
Start Command: pnpm start --filter=frontend
Do the same for the backend service.
Note that you should have build/start scripts in backend/package.json and frontend/package.json .
I host a pnpm monorepo here on Railway, and it works with no problems. Hope this helps.
12 days ago
You can check this Railway guide on how to deploy a monorepo as well.
12 days ago
the start command worked, Ive just not done that before because in my mind I would not have any reason to do so
but anyways thanks a lot for your help
Status changed to Solved brody • 12 days ago
