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 advance
Railway Variables
The env using in React
16 Replies
Percy
Percy13mo ago
Project ID: e436ca45-aec0-4dba-9ed4-9c4703e598fb
Brody
Brody13mo ago
is this a react scripts based app?
confidentmuscle
confidentmuscle13mo ago
I'm sorry I didn't understand that
confidentmuscle
confidentmuscle13mo ago
No I'm not using create react app
Brody
Brody13mo ago
what are you using then
confidentmuscle
confidentmuscle13mo ago
I'm using parcel
Brody
Brody13mo ago
is parcel setup to read variables from the environment when no .env file exists?
confidentmuscle
confidentmuscle13mo ago
No I think it's not It uses dotenv And requires .env file for the variables
Brody
Brody13mo ago
well there's the issue
confidentmuscle
confidentmuscle13mo ago
Oh ok, But how can use the env variables without the .env file
Brody
Brody13mo ago
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
Olllie
Olllie11mo ago
Hey, did you ever work this out. I'm having the same issue. Can't seem to access the variables through railway.app
Brody
Brody11mo ago
have you set the variables in the service variables and are they prefixed with the correct prefix?
Olllie
Olllie11mo ago
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
Brody
Brody11mo ago
okay can we move this to a new thread please? aka open your own