Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev server doesn't update overridden env var when doing an automatic reload. #17519

Open
7 tasks done
alexkreidler opened this issue Jun 19, 2024 · 1 comment
Open
7 tasks done

Comments

@alexkreidler
Copy link

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 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

Reproduction

https://stackblitz.com/edit/vitejs-vite-y1ptn5?file=main.js,.env,.env.development&terminal=dev

Steps to reproduce

  1. Put VITE_PUBLIC_API_URL=https://api.mysite.com in .env.
  2. 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.
  3. 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.
Screenshot 2024-06-19 at 04-00-12 Vitejs - Vite (forked) - StackBlitz

System Info

System:
    OS: Linux 5.15 Ubuntu 22.04.4 LTS 22.04.4 LTS (Jammy Jellyfish)
    CPU: (16) x64 AMD Ryzen 7 3800X 8-Core Processor
    Memory: 11.82 GB / 15.56 GB
    Container: Yes
    Shell: 3.7.0 - /usr/bin/fish
  Binaries:
    Node: 18.14.0 - ~/.volta/tools/image/node/18.14.0/bin/node
    Yarn: 3.6.1 - ~/.volta/tools/image/yarn/1.22.19/bin/yarn
    npm: 9.3.1 - ~/.volta/tools/image/node/18.14.0/bin/npm
    pnpm: 8.6.5 - ~/.local/share/pnpm/pnpm
    bun: 0.5.8 - ~/.volta/bin/bun
    Watchman: 2023.12.04.00 - /home/linuxbrew/.linuxbrew/bin/watchman
  Browsers:
    Chrome: 123.0.6312.105
    Chromium: 126.0.6478.61

Used Package Manager

pnpm

Logs

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...

Validations

Copy link

stackblitz bot commented Jun 19, 2024

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant