a month ago
I'm using VITE env variables for stuff, I want to add 2 new variables, i add them and they don't work, i am following the correct naming but they just don't seem to want to show up after the image is deployed. Weirdest thing is, on dev it was showing up fine and it shows the values from .env
Pinned Solution
a month ago
If you are using a Dockerfile to deploy your app, vite variables must be explicitly declared in your Dockerfile.
The fact that the top 3 work suggests you are using a custom Dockerfile where you previously added ARG lines for those 3 variables, but you haven't added ARG lines for the 2 new ones yet.ARG VITE_APP_API_URL
ARG VITE_APP_WS_URL
ARG VITE_MAPBOX_ACCESS_TOKEN
# Add the new ones:
ARG VITE_APP_COMPANY
ARG VITE_APP_PSW
ENV VITE_APP_API_URL=$VITE_APP_API_URL
ENV VITE_APP_WS_URL=$VITE_APP_WS_URL
ENV VITE_MAPBOX_ACCESS_TOKEN=$VITE_MAPBOX_ACCESS_TOKEN
# Add the new ones here too:
ENV VITE_APP_COMPANY=$VITE_APP_COMPANY
ENV VITE_APP_PSW=$VITE_APP_PSW
RUN npm run build
Hope this helps.
14 Replies
a month ago
Are you correctly adding the prefix VITE_ to those env vars?
I'd like to clear up that most env variable with VITE_ prefix are working, the first ones i added for api connection and some other stuff worked fine
I've tried loading different browsers entirely to check if it's cache or smth but nothing fixes , they just come up as empty strings when i call them
a month ago
are you using docker to deploy the app?
yes I am. the weirdest thing about it is that it's working on dev but i deploy a new image with the variables on railway and they just don't work. Again, some do but some don't on railway
a month ago
What are the variable names like?
I've tried different naming, I've tried copying the whole VITE naems above and just replacing the URL for example to COMPANY from the top one, all variables are also called in the same way but on dev they work fine, live they just don't
a month ago
Providing a reproducible example will greatly increase the community's ability to help you solve your problem!
a month ago
If you are using a Dockerfile to deploy your app, vite variables must be explicitly declared in your Dockerfile.
The fact that the top 3 work suggests you are using a custom Dockerfile where you previously added ARG lines for those 3 variables, but you haven't added ARG lines for the 2 new ones yet.ARG VITE_APP_API_URL
ARG VITE_APP_WS_URL
ARG VITE_MAPBOX_ACCESS_TOKEN
# Add the new ones:
ARG VITE_APP_COMPANY
ARG VITE_APP_PSW
ENV VITE_APP_API_URL=$VITE_APP_API_URL
ENV VITE_APP_WS_URL=$VITE_APP_WS_URL
ENV VITE_MAPBOX_ACCESS_TOKEN=$VITE_MAPBOX_ACCESS_TOKEN
# Add the new ones here too:
ENV VITE_APP_COMPANY=$VITE_APP_COMPANY
ENV VITE_APP_PSW=$VITE_APP_PSW
RUN npm run build
Hope this helps.
you are correct, darseen, taht was definitely the problem. Sorry i couldn't provide more context, it's not really my project and wasn't sure how much i could share
Status changed to Solved brody • about 1 month ago
