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?
![No description](https://cdn.answeroverflow.com/1197509676561080350/Screenshot_2024-01-18_at_5.25.25_PM.png)
![No description](https://cdn.answeroverflow.com/1197509676871467088/Screenshot_2024-01-18_at_5.25.47_PM.png)
@Brody could you please help?
( #🛂|readme #5 )
Could it be possible that the variable is not accessible during build stage ![thonk](https://cdn.discordapp.com/emojis/969365165688635464.png)
![thonk](https://cdn.discordapp.com/emojis/969365165688635464.png)
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