[go: up one dir, main page]

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

Environment variables not hot-reloaded after editing .env files #10025

Open
clemyan opened this issue Sep 24, 2024 · 1 comment
Open

Environment variables not hot-reloaded after editing .env files #10025

clemyan opened this issue Sep 24, 2024 · 1 comment

Comments

@clemyan
Copy link
clemyan commented Sep 24, 2024

Reproduction

  1. Go to https://stackblitz.com/edit/remix-run-remix-semm1n?file=.env.local
  2. See X = "1" is rendered on screen
  3. Edit .env.local to X = 2 and save (Also works on .env, but StackBlitz does not persist .env files so using .env.local for demo)
  4. The Vite server reloads, but still renders X = "1"
  5. Manually stop and restart the server (npm run dev)
  6. When the server starts up again, X = "2" is rendered

System Info

System:
    OS: Windows 10 10.0.19045
    CPU: (16) x64 Intel(R) Core(TM) i7-10700 CPU @ 2.90GHz
    Memory: 5.94 GB / 31.87 GB
  Binaries:
    Node: 20.17.0 - C:\Program Files\nodejs\node.EXE      
    Yarn: 4.5.0 - C:\Program Files\nodejs\yarn.CMD        
    npm: 10.8.2 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Chromium (127.0.2651.74)
    Internet Explorer: 11.0.19041.4355
  npmPackages:
    @remix-run/dev: ^2.12.1 => 2.12.1 
    @remix-run/node: ^2.12.1 => 2.12.1 
    @remix-run/react: ^2.12.1 => 2.12.1 
    @remix-run/serve: ^2.12.1 => 2.12.1 
    vite: ^5.1.0 => 5.4.0

Used Package Manager

npm

Expected Behavior

In development (remix vite:dev), after editing .env files, the app re-renders or reloads with the new environment variables

Actual Behavior

The app sees the old variables, even after full page reloads.

@laishere
Copy link

Just tested. It seems for the variables already exist, they won't be reloaded.
However, when we set a new variable, it is loaded correctly.

After checking how vite handles .env, I found it's an expected behavior from package dotenv-expand.

  1. Vite:
    https://github.com/vitejs/vite/blob/768a50f7ac668dbf876feef557d8c0f8ff32b8ff/packages/vite/src/node/env.ts#L55
  2. dotenv-expand:
    https://github.com/motdotla/dotenv-expand/blob/ff7e2efd0d9925c7da82c167ae77d22a6c76e878/lib/main.js#L70-L71

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

3 participants