I'm having a lot of trouble getting the pre-deploy command to run
johncch
HOBBYOP

2 months ago

I keep ending up with pre-deploy command failed errors like these:
My pre-deploy command is not fancy. It's just npx prisma migrate deploy or stuffing that into scripts and calling pnpm run db:migrate and they all fail.

What am I doing wrong and how can I get better debugging?

Attachments

Solved$10 Bounty

Pinned Solution

domehane
FREE

2 months ago

the pre-deploy command can't find prisma because it's probably in your devDependencies and railway doesn't install those in production.

two ways to fix this;

option 1 iz to move prisma to regular dependencies in package.json

npm install prisma --save

then delete node_modules and lockfile, run npm install, commit and push

option 2 is to add this environment variable in railway:

  • name: NPM_CONFIG_PRODUCTION

  • value: false

also double check that DATABASE_URL is actually set in your railway environment variables

and i think the empty logs happen because prisma cli isn't even available when the pre-deploy tries to run. once prisma is installed properly the logs should show up and it should work

8 Replies

Railway
BOT

2 months ago

Hey there! We've found the following might help you get unblocked faster:

If you find the answer from one of these, please let us know by solving the thread!


Can you provide deployment logs? There might be errors in there that will help explain what's going on.


johncch
HOBBYOP

2 months ago

The deployment logs are completely empty! The build one builds successfully.


jonhvmp
FREE

2 months ago

Likely the database isn't ready when pre-deploy runs. Try removing the pre-deploy command and putting everything in the start command:

`/bin/sh -c "npx prisma migrate deploy && pnpm start"`

The /bin/sh -c forces Railway to keep the process alive. This usually fixes it when logs are empty.

Also check if Prisma is in dependencies (not devDependencies) in your package.json


domehane
FREE

2 months ago

the pre-deploy command can't find prisma because it's probably in your devDependencies and railway doesn't install those in production.

two ways to fix this;

option 1 iz to move prisma to regular dependencies in package.json

npm install prisma --save

then delete node_modules and lockfile, run npm install, commit and push

option 2 is to add this environment variable in railway:

  • name: NPM_CONFIG_PRODUCTION

  • value: false

also double check that DATABASE_URL is actually set in your railway environment variables

and i think the empty logs happen because prisma cli isn't even available when the pre-deploy tries to run. once prisma is installed properly the logs should show up and it should work


aymenkani
FREE

2 months ago

The issue might actually be deeper than just a missing env var or a database delay. It is often related to how Prisma binaries are packaged during the build process.

I have a Node.js + Prisma + Redis template that solves this specific issue. It’s pre-configured to handle the packaging correctly and runs migrations safely in the pre-deploy stage. You can check it out here: https://railway.com/deploy/nodejs-multimodal-rag-starter?referralCode=2psx_t&utm_medium=integration&utm_source=template&utm_campaign=generic


johncch
HOBBYOP

2 months ago

Thanks all for your help.

It turns out, the issue was that prisma was not available in the final built image. These things helped:

1. Having /bin/sh -c "<command"> was really helpful to see error messages

  1. It turns out having prisma in devDependencies were not sufficient; next js standalone build prunes unrelated node_modules. I had to manually copy node_modules in the final stage in the dockerfile.

  2. I tried doing a npm install -g prisma@7.2.0 but that didn't work because prisma.config.ts needed a few other dependencies.

It's not an ideal solution, but good enough for now. Thanks all!


domehane
FREE

2 months ago

nice! you got it figured out. looks like the core issue i mentioned was right (prisma not available in the final image) but i didn't account for the next.js standalone build specifically ; that's more complex than the standard railway deployment

the /bin/sh -c "<command>" wrapper to see error messages is a great tip i didn't know about , that's why your logs were empty

so yeah my answer about devDependencies would've helped for a basic node app, but your dockerfile with next.js standalone was doing its own pruning which needed that manual node_modules copy in the final stage

glad you solved it! and that /bin/sh wrapper trick is gold for debugging empty pre-deploy logs


Status changed to Solved brody about 2 months ago


Loading...