9 months ago
On an express project with typescript inside a monorepo with turborepo, when deploying the server can't access the environment variables of railway, and I think the code is good because in local it's working
31 Replies
9 months ago
Hey, just a few question to help me debug this -
- Have you deployed the changes after setting the service variables, if you haven't they will be highlighted blue and you will need to click the Deploy button.
- Are you using a Dockerfile or Nixpacks?
9 months ago
I deployed the changes and im not using nixpacks or dockerfile
9 months ago
On Railway it would be one or the other, meaning you are most likely using nixpacks
But can you confirm this for me, open up your latest deployment and go into the details tab.
9 months ago
the builder says nixpack
9 months ago
this is supposed to happen when there is no env variable, but in local it's working good, im using turbo btw
9 months ago
that is a log from railway
9 months ago
yeah i think so
9 months ago
like this?
9 months ago
still getting the error
9 months ago
Would you mind sending a screenshot of your service variables? no need to unhide anything.
9 months ago
here
9 months ago
I'm honestly stumped, something in your codebase is "unsetting" them, i'm just not sure what that could be. I will have to leave this to a team member, perhaps they will have more ideas.
9 months ago
Does this have something to do with my issue?
9 months ago
Super weird, i have another deploy with turborepo as well and the envs are working
9 months ago
Can you share a link to the service this is happening in? I'll check to see if your workload is actually getting those variables injected properly
Status changed to Awaiting User Response railway[bot] • 9 months ago
9 months ago
any updates on this? I believe the issue is turbo.json, because within it i specified .env as a global dependency, making it work on my local. however im guessing railway does something different. im getting the exact same issue using zod.
here is the turbo.json in a specific app, so "/apps/<app-name>"
9 months ago
i solved the issue, by downgrading turbo to: "1.13.3"
Status changed to Awaiting Railway Response railway[bot] • 9 months ago
9 months ago
this is my tubo.json:
9 months ago
Railway does not create an .env file for you, instead the environment variables are injected into the environment.
So if your code is only looking to load variables from a file your variables would appear to be missing.
Status changed to Awaiting User Response railway[bot] • 9 months ago
9 months ago
This looks like what could be causing your issue -
https://turbo.build/repo/docs/crafting-your-repository/using-environment-variables#strict-mode
9 months ago
I'm running into the same issue with the latest version of Turborepo—it just won't read environment variables. I tried using "turbo run build --env-mode=loose," but no luck. I've dealt with this problem before and had to roll back to an older version of Turborepo to fix it. Now, I'm stuck and can't find a solution.
Status changed to Awaiting Railway Response railway[bot] • 9 months ago
Status changed to Awaiting User Response railway[bot] • 9 months ago
5 months ago
I had the same problem, I fixed it by adding globalEnv with the required variables to turbo.json
Status changed to Awaiting Railway Response railway[bot] • 5 months ago
Status changed to Solved brody • 5 months ago
2 hours ago
Hey, just encountered this issue. A quick solution is to set envMode
to loose
on your turbo.json
, but the long term solution (as suggested by brody) is to list environment variables needed on each task.
The turborepo docs on this are pretty good: https://turborepo.com/docs/crafting-your-repository/using-environment-variables#strict-mode
Attachments
Status changed to Open railway[bot] • about 2 hours ago
Status changed to Solved brody • about 2 hours ago