2 months ago
I am trying to deploy a Node.js backend located in a subdirectory (/server) of a monorepo. Despite configuring the Root Directory to server (both via UI settings and railway.json), the deployment appears to be executing the Rootpackage.json scripts instead of the Serverpackage.json scripts.
This causes the deployment to crash because it attempts to run frontend commands (vite, client) in the backend environment which does not have those dependencies installed.
Repository Structure
Plaintext
/ (Root)
├── package.json (Contains "concurrently" scripts for local dev)
├── railway.json (Configured with "rootDirectory": "server")
├── .gitignore
└── server/
├── package.json (The actual backend config)
├── prisma/
└── src/
Configuration
railway.json:
JSON
{ "build": { "rootDirectory": "server" }, "deploy": { "startCommand": "npx prisma db push && node src/index.js", "restartPolicyType": "ON_FAILURE" } }UI Settings > Build > Root Directory: Set to
server
Error Logs
The deployment logs show the process exiting with code 127 and vite: not found. This indicates it is running the npm start script from the ROOTpackage.json (which tries to run the client) instead of the SERVERpackage.json (which runs the API).
Plaintext
[1] > client@0.0.0 dev
[1] > vite
[1] sh: 1: vite: not found
[1] npm run client exited with code 127
[0] npm run server exited with code 1
Troubleshooting Steps Taken
Verified
railway.jsonis present in the absolute root of the repository.Verified
server/package.jsoncontains the correct start scripts and dependencies.Manually set "Root Directory" to
serverin Railway Service Settings.Cleared Git cache and force-pushed to remove any
node_modulespollution.Added
postinstall: npx prisma generatetoserver/package.json.
Request
Can you please check why the build context is not switching to the /server directory? It seems to be persisting at the Root level despite configuration.
0 Replies