You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a production API url and a local API URL I am trying to put into .env.local or .env.development. But after upgrading from vite 4.5.3 to 5.3.1, I noticed the dev server is not applying env vars correctly when doing an automatic reload.
Note that the frontend shows the correct value when killing the dev server and manually re-running from terminal
Put VITE_PUBLIC_API_URL=https://api.mysite.com in .env.
Add VITE_PUBLIC_API_URL=http://localhost:3100 in .env.local. After refreshing the frontend console.log(import.meta.env.VITE_PUBLIC_API_URL); shows the https://api.mysite.com value.
Do the same thing in .env.development, deleting .env.local, frontend still shows the old value
In StackBlitz you may have to delete .env.development, manually restart the server and then re-add it to reproduce.
3:41:26 AM [vite] .env.local changed, restarting server...
3:41:26 AM [vite] server restarted.
3:42:06 AM [vite] .env.development changed, restarting server...
3:42:06 AM [vite] server restarted.
3:42:16 AM [vite] .env changed, restarting server...
Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
Describe the bug
I have a production API url and a local API URL I am trying to put into
.env.local
or.env.development
. But after upgrading from vite4.5.3
to5.3.1
, I noticed the dev server is not applying env vars correctly when doing an automatic reload.Note that the frontend shows the correct value when killing the dev server and manually re-running from terminal
Reproduction
https://stackblitz.com/edit/vitejs-vite-y1ptn5?file=main.js,.env,.env.development&terminal=dev
Steps to reproduce
VITE_PUBLIC_API_URL=https://api.mysite.com
in.env
.VITE_PUBLIC_API_URL=http://localhost:3100
in.env.local
. After refreshing the frontendconsole.log(import.meta.env.VITE_PUBLIC_API_URL);
shows thehttps://api.mysite.com
value..env.development
, deleting.env.local
, frontend still shows the old valueIn StackBlitz you may have to delete
.env.development
, manually restart the server and then re-add it to reproduce.System Info
Used Package Manager
pnpm
Logs
Validations
The text was updated successfully, but these errors were encountered: