Vite Env variables is undefined for react project
I am using Vite + React for my FE.
On my local I am using
.env
to add VITE_API_URL
that can be accessed like import.meta.env.VITE_API_URL
so that I can make API request but upon viewing in the network tab I can see that it is undefined.
I added the variable in railway from the Variables tab. Also I am using serve to serve the build files.
Below are the scripts in my package.json
14 Replies
Project ID:
ed9d81eb-a192-462c-8cf6-bf7778244e57
Project ID:
ed9d81eb-a192-462c-8cf6-bf7778244e57
ed9d81eb-a192-462c-8cf6-bf7778244e57
so you're uploading a
.env
file to railway?no not uploading but using the variable section from railway dashboard
oh okay
I'm personally not sure what's wrong here since I don't use Vite or React
so let's wait for someone who knows to step in
Okay
I have added my variable here then why is it undefined?
@Brody could you please help?
( #🛂|readme #5 )
Could it be possible that the variable is not accessible during build stage
Noted
Anyways I was able to solve this issue. I was using docker but I saw other post where it was metioned to use nixpacks instead of docker so I removed the dockerfile and added dependency from VITE + React template and it worked.
I'm glad to hear that 🔥
Sorry that I couldn't be of more help
glad you figured it out :)
No issues, thanks anyways