Deployment crashing - Root Directory config appears ignored (Vite/Concurrent error in Backend)
dainantonio
HOBBYOP

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

  1. Verified railway.json is present in the absolute root of the repository.

  2. Verified server/package.json contains the correct start scripts and dependencies.

  3. Manually set "Root Directory" to server in Railway Service Settings.

  4. Cleared Git cache and force-pushed to remove any node_modules pollution.

  5. Added postinstall: npx prisma generate to server/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.

$10 Bounty

0 Replies

Loading...