Im struggling to configure my monorepo for the frontend (react)
souzaricardo
HOBBYOP

4 months 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 respond

This 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

Solved$10 Bounty

Pinned Solution

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 4 months ago


xmrafonso
FREE

4 months ago

Hey,

Do you have any errors or exit codes from the crashes?

Have you tried adding each individually as a separate services?


souzaricardo
HOBBYOP

4 months 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?

souzaricardo
HOBBYOP

4 months ago

At this moment they are separated yes


souzaricardo

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
FREE

4 months 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.

souzaricardo
HOBBYOP

4 months 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 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

xmrafonso
FREE

4 months 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.

souzaricardo
HOBBYOP

4 months 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


xmrafonso
FREE

4 months ago

.


souzaricardo

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

xmrafonso
FREE

4 months 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.


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.


You can check this Railway guide on how to deploy a monorepo as well.


souzaricardo
HOBBYOP

4 months 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 4 months ago


Welcome!

Sign in to your Railway account to join the conversation.

Loading...