Deploy with turborepo can't access the environment variables

biggabo
PRO

a year 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

Solved

31 Replies

a year 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?


biggabo
PRO

a year ago

I deployed the changes and im not using nixpacks or dockerfile


a year 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.


biggabo
PRO

a year ago

the builder says nixpack


a year ago

Thanks, can you share the specific error(s) you are getting?


biggabo
PRO

a year ago

this is supposed to happen when there is no env variable, but in local it's working good, im using turbo btw


biggabo
PRO

a year ago

that is a log from railway


a year ago

You are having zod load from process.env correct?


biggabo
PRO

a year ago

yeah i think so


a year ago

Can you try removing / commenting out the dotenv lines?


biggabo
PRO

a year ago

like this?


a year ago

Exactly!


biggabo
PRO

a year ago

alright im deploying to see


biggabo
PRO

a year ago

still getting the error


a year ago

Would you mind sending a screenshot of your service variables? no need to unhide anything.


biggabo
PRO

a year ago

here


a year 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.


biggabo
PRO

a year ago

Oh no problem, thanks anyway


biggabo
PRO

a year ago

Does this have something to do with my issue?


a year ago

It does not.


biggabo
PRO

a year ago

Super weird, i have another deploy with turborepo as well and the envs are working


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] 11 months ago


sarmanaulakh
BIZCLASS

a year 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>"


biggabo
PRO

a year ago

i solved the issue, by downgrading turbo to: "1.13.3"


Status changed to Awaiting Railway Response railway[bot] 11 months ago


biggabo
PRO

a year ago

this is my tubo.json:


a year 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] 11 months ago



aimanager-code
HOBBY

10 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] 11 months ago


10 months ago

Have you tried specifying your needed envs in your turbo.json ?


Status changed to Awaiting User Response railway[bot] 11 months ago


victorius19
PRO

7 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] 7 months ago


Status changed to Solved brody 7 months ago


thisislvca
PRO

2 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[bot] about 2 months ago


Status changed to Solved brody about 2 months ago