React Application showing undefined env variables when deployed
Project Id : e436ca45-aec0-4dba-9ed4-9c4703e598fb
Hey everyone, it's my first time using railway to deploy my app. I've a react client and an express server for which I've created docker images and deployed them using railway, but there are some env variables like db credentials, api urls for which I've used the variables in railway. Everything in the Express server is working fine, but in the React client for which I've used parcel to build and serving through ngnix the env variables are always showing undefined.
When I'm running the docker image in my local system it's working well and all the env variables are working as they should but when I'm deploying them in railway they are getting undefined
.env file
REACT_APP_API_URL=api-some-app.com
I need the above env to call an API which I don't want to expose in the code, Is there any other way I can solve this?
Can someone please tell me if I'm doing something wrong here.Thanks in advance16 Replies
Project ID:
e436ca45-aec0-4dba-9ed4-9c4703e598fb
is this a react scripts based app?
I'm sorry I didn't understand that
No I'm not using create react app
what are you using then
I'm using parcel
is parcel setup to read variables from the environment when no .env file exists?
No I think it's not
It uses dotenv
And requires .env file for the variables
well there's the issue
Oh ok, But how can use the env variables without the .env file
you've set the variables in the service variables in railway, railway injects those variables into the environment, you just need to get parcel to read the variables from the environment
Hey, did you ever work this out. I'm having the same issue. Can't seem to access the variables through railway.app
have you set the variables in the service variables and are they prefixed with the correct prefix?
Yep, I've peeled it right back and am currently just trying to get this one to console log in my front end. But its returning undefined. Its console logging fine in the railway deploy logs
okay can we move this to a new thread please? aka open your own