a month ago
Hi everyone,
I'm trying to deploy a MedusaJS B2B starter project to Railway, but the build is consistently failing during the yarn install step.
The core issue seems to be that the build process can't find the DATABASE_URL environment variable, even though I have correctly configured it in my Railway project's variables tab.
My Setup:
Project: MedusaJS (B2B Starter)
Platform: Railway
Package Manager: Yarn 4.4.0
Key Script (
package.json): Mypostinstallscript runs database migrations:"postinstall": "yarn medusa db:create && yarn medusa db:migrate"
The Problem: The build process fails because the postinstall script is automatically triggered after yarn install. This script requires a database connection to run migrations, but it exits with an error saying the DATABASE_URL is missing.
I have already added DATABASE_URL to the environment variables in the Railway dashboard. It seems like the variables are not available during the build phase when yarn install and the postinstall script are executed.
What I've already checked:
The
DATABASE_URLis definitely set in the Railway environment variables for the project.I've double-checked for any typos in the variable name.
The build works if I remove the database-related commands from the
postinstallscript, which confirms the issue is with accessing the variable during build time.
My main question is: How can I make the DATABASE_URL available during the build phase on Railway so my postinstall script can run migrations successfully? Is there a different approach I should take for running migrations on deployment?
Here is the relevant part of the build log:
➤ YN0000: ┌ Link step
➤ YN0007: │ @swc/core@npm:1.13.20 [bbc7f] must be built because it never has been before or the last one failed
➤ YN0007: │ @medusajs/telemetry@npm:2.8.8 must be built because it never has been before or the last one failed
➤ YN0007: │ esbuild@npm:0.21.5 must be built because it never has been before or the last one failed
➤ YN0007: │ msgpackr-extract@npm:3.0.3 must be built because it never has been before or the last one failed
➤ YN0007: │ medusa-b2b-starter@workspace:. must be built because it never has been before or the last one failed
➤ YN0000: │ medusa-b2b-starter@workspace:. STDOUT {"level":"error","message":"Missing \"DATABASE_URL\" inside the .env file. The value is required to connect to the PostgreSQL server","timestamp":"2025-10-08 11:50:19"}
➤ YN0009: │ medusa-b2b-starter@workspace:. couldn't be built successfully (exit code 1, logs can be found here: /tmp/xfs-5849ff8e/build.log)
➤ YN0000: └ Completed in 18s 262ms
➤ YN0000: · Failed with errors in 25s 523ms
ERROR: failed to build: failed to solve: process "yarn install --check-cache" did not complete successfully: exit code: 1
Thanks in advance for any help!
4 Replies
a month 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!
a month ago
This thread has been marked as public for community involvement, as it does not contain any sensitive or personal information. Any further activity in this thread will be visible to everyone.
Status changed to Open brody • about 1 month ago
a month ago
Remove migrations from postinstall.
Run migrations at runtime or as a one-off command.
a month ago
They seem to recommend running migrations as a predeploy step - rather than a postinstall yarn/npm hook.
https://docs.railway.com/guides/pre-deploy-command
a month ago
Do you still need help on this one? I have tried to reinstall a new instance of this and works fine on my end.