2 years 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
2 years 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?
2 years ago
I deployed the changes and im not using nixpacks or dockerfile
2 years 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.
2 years ago
the builder says nixpack
2 years ago

this is supposed to happen when there is no env variable, but in local it's working good, im using turbo btw
2 years ago
that is a log from railway
2 years ago
yeah i think so
2 years ago
like this?
2 years ago
still getting the error
2 years ago
Would you mind sending a screenshot of your service variables? no need to unhide anything.
2 years ago

here
2 years 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.
2 years ago
Does this have something to do with my issue?
2 years ago
Super weird, i have another deploy with turborepo as well and the envs are working
2 years 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 • over 1 year ago
2 years 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>"
2 years ago
i solved the issue, by downgrading turbo to: "1.13.3"

Status changed to Awaiting Railway Response Railway • over 1 year ago
2 years ago
this is my tubo.json:
2 years 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 • over 1 year ago
2 years ago
This looks like what could be causing your issue -
https://turbo.build/repo/docs/crafting-your-repository/using-environment-variables#strict-mode
2 years 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 • over 1 year ago
Status changed to Awaiting User Response Railway • over 1 year ago
a year 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 • about 1 year ago
Status changed to Solved brody • about 1 year ago
10 months 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 • 10 months ago
Status changed to Solved brody • 10 months ago


