Cannot deploy Monorepo properly

deshartman
FREE

2 months ago

I checked through the docs and issues here, but still cannot find a solution. If I deploy https://github.com/deshartman/simple-conversation-relay without a root directory setting, it all works no problem, even though the monorepo docs say to use a root path..

If I add a root path of /server, I hit the below issues. Could you please assist in the right config for this setup?

> simple-conversation-relay-server@3.0.0 start

May 22 14:07:11

> node dist/server.js

May 22 14:07:11

ode:internal/modules/cjs/loader:1228

May 22 13:35:45

throw err;

May 22 13:35:45

^

May 22 13:35:45

May 22 13:35:45

Error: Cannot find module '/app/dist/server.js'

May 22 13:35:45

at Module._resolveFilename (node:internal/modules/cjs/loader:1225:15)

May 22 13:35:45

at Module._load (node:internal/modules/cjs/loader:1051:27)

May 22 13:35:45

at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:174:12)

May 22 13:35:45

at node:internal/main/run_main_module:28:49 {

May 22 13:35:45

code: 'MODULE_NOT_FOUND',

May 22 13:35:45

requireStack: []

May 22 13:35:45

}

May 22 13:35:45

May 22 13:35:45

Node.js v20.18.0

$10 Bounty

1 Replies

bogdan144
FREE

2 months ago

The error you're facing:

Error: Cannot find module '/app/dist/server.js'

means that Railway is trying to run a file (dist/server.js) that doesn’t exist yet, because the project wasn't built before starting.

This happens in monorepo setups when you:

  • Set a root path (like /server)

  • But don’t build the code before running it.

Solution for Railway Deployment

To fix this in Railway, update your railway.json or project settings like this:

railway.json (or GUI settings if you're using the dashboard):

{
  "root": "server",
  "buildCommand": "npm install && npm run build",
  "startCommand": "npm start"
}

Also check the server/package.json:

Make sure it has a build script:

"scripts": {
  "build": "tsc",
  "start": "node dist/server.js"
}

Or if using Babel:

"build": "babel src -d dist"

The important thing is that npm run build must create dist/server.js.

Final Steps

  1. Go to Railway → Deployments

  2. Set Root Directory = server

  3. Set Build Command = npm install && npm run build

  4. Set Start Command = npm start

  5. Redeploy

Let me know if you want me to look at your actual repo or help prepare the railway.json file — I can do that too.