5 months ago
Even declaring the variables on turbo.json, on Railway still undefined
That's my turbo.json on the /apps/server directory:
{
"extends": ["//"],
"tasks": {
"build": {
"dependsOn": ["^build"],
"inputs": [
"$TURBO_DEFAULT$",
".env.production.local",
".env.local",
".env.production",
".env"
],
"outputs": ["dist/**", ".next/**", "!.next/cache/**"],
"env": ["DATABASE_URL", "NODE_ENV", "PORT"]
},
"dev": {
"cache": false,
"persistent": true,
"inputs": [
"$TURBO_DEFAULT$",
".env.production.local",
".env.local",
".env.production",
".env"
],
"env": ["DATABASE_URL", "NODE_ENV", "PORT"]
}
}
}16 Replies
5 months ago
Declaring
envinturbo.jsondoes not assign values — it only defines which variables should be passed if they exist.Go to Railway Dashboard > Variables section and manually add your environment variables, for example:
DATABASE_URL=your_valueNODE_ENV=productionPORT=8000
If you're using
.envfiles, make sure to load them manually in your entry file using:jsCopyEdit
require('dotenv').config();Now
process.env.DATABASE_URLand others will work correctly at build and runtime.
5 months ago
You could try enabling Turborepo's loose mode.
I did that, and it solved. But their docs on the strict mode (the recommend way) is very bad imo. Do you know how to properly handle that?
5 months ago
I unfortunately am not familiar with Turborepo, perhaps you can try asking in the Vercel forum with the Turborepo tag.
5 months ago
sorry to volunteer you @ThallesComH but you are a turborepo expert
5 months ago
If you're specifying all the environment variables in turbo.json, then it should just work.
Also, it seems like you're creating a turbo.json per app/workspace, which may be causing that issue, and as far as I know, that's incorrect. The turbo.json file should be located at the root directory only.
Should I specify all the environment variables of all the workspaces on the “env” property inside the build step then?
5 months ago
yep, if you want there's [globalEnv]() at root to set for all steps too.
5 months ago
btw, if you're using a Dockerfile and attempting to access environment variables at build time, be aware that you'll need to modify your Dockerfile a bit.
5 months ago
If you're accessing environment variables at build time (such as process.env.) and you're using a Dockerfile or any tool that requires those environment variables during build time, Railway requires you to modify your code slightly. This isn't related to Turborepo, but I wanted to ensure you're not affected by this circumstance.
5 months ago
for example running a database migration at build time where it needs the DATABASE_URL at that stage.
5 months ago
Hey @pedro, do you still need help with setting up your turbo.json for envs?
5 months ago
!s
Status changed to Solved uxuz • 5 months ago