R
Railway10mo ago
Screeper

ENV variable doesn't get overwritten properly

./frontend/.env
REACT_APP_BACKEND=http://localhost:3001
REACT_APP_BACKEND=http://localhost:3001
./frontend/src/App.tsx
...
await axios.get(`${process.env.REACT_APP_BACKEND}/api`);
...
...
await axios.get(`${process.env.REACT_APP_BACKEND}/api`);
...
This works locally as it requests localhost. My desired behavior that it should request backend.customdomain.com when deployed to Railway, but it still requests localhost. I have attached two pictures that I set my variable to the correct value on Railway and I set my root directory to ./frontend. I have tried reading the docs, but I can't figure out what am I doing wrong. Can you please help me?
No description
No description
Solution:
Pushing your .env to production is almost certainly the issue, as it may be overwriting existing environment variable that you've set in Railway with options from your .env.
Jump to solution
7 Replies
Percy
Percy10mo ago
Project ID: 43338470-7ca1-41cf-a9f1-e58be877d64c
Screeper
Screeper10mo ago
My guess is that it wants the .env to be in the very root of the project and not in the root of the frontend directory (I have a monorepo set up)
Fragly
Fragly10mo ago
Why are you pushing your .env to production?
macwilko
macwilko10mo ago
You might find this guide helpful if you're deploying a monorepo
Solution
root
root10mo ago
Pushing your .env to production is almost certainly the issue, as it may be overwriting existing environment variable that you've set in Railway with options from your .env.
Fragly
Fragly10mo ago
This adding your .env to your .gitignore file and update, all your .env values should be added in your Railway Service Variables
Want results from more Discord servers?
Add your server