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
> node dist/server.js
ode:internal/modules/cjs/loader:1228
throw err;
^
Error: Cannot find module '/app/dist/server.js'
at Module._resolveFilename (node:internal/modules/cjs/loader:1225:15)
at Module._load (node:internal/modules/cjs/loader:1051:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:174:12)
at node:internal/main/run_main_module:28:49 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
Node.js v20.18.0
1 Replies
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 createdist/server.js
.
Final Steps
Go to Railway → Deployments
Set Root Directory =
server
Set Build Command =
npm install && npm run build
Set Start Command =
npm start
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.