VITE variables just wont apply for some reason
blendibrahimi1
FREEOP

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

Solved$10 Bounty

Pinned Solution

darseen
HOBBYTop 1% Contributor

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

medim
MODERATOR

a month ago

Are you correctly adding the prefix VITE_ to those env vars?


blendibrahimi1
FREEOP

a month ago

yep, the naming is correct since in dev they do show up correctly


blendibrahimi1
FREEOP

a month ago

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


blendibrahimi1
FREEOP

a month ago

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


fra
HOBBYTop 10% Contributor

a month ago

are you using docker to deploy the app?


blendibrahimi1
FREEOP

a month ago

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


aldrinm
HOBBY

a month ago

What are the variable names like?


blendibrahimi1
FREEOP

a month ago

top 3 work, bottom 2 don't

1459286620220948700


blendibrahimi1
FREEOP

a month ago

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


blendibrahimi1
FREEOP

a month ago

top 3 were set when the service was first made


brody
EMPLOYEE

a month ago

Providing a reproducible example will greatly increase the community's ability to help you solve your problem!


darseen
HOBBYTop 1% Contributor

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.


blendibrahimi1
FREEOP

a month ago

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


blendibrahimi1
FREEOP

a month ago

Again, thank you


Status changed to Solved brody about 1 month ago


Loading...