10 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
Pinned Solution
10 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 --savethen 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
10 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!
10 months ago
Can you provide deployment logs? There might be errors in there that will help explain what's going on.
10 months ago
The deployment logs are completely empty! The build one builds successfully.
10 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
10 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 --savethen 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
10 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%5Ft&utm%5Fmedium=integration&utm%5Fsource=template&utm%5Fcampaign=generic
10 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
- It turns out having
prismain 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. - I tried doing a
npm install -g [email protected]but that didn't work becauseprisma.config.tsneeded a few other dependencies.
It's not an ideal solution, but good enough for now. Thanks all!
10 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 • 10 months ago