Skip to content

Changing environment variables restarts Vite server but doesn't actually update value #9587

@VHall1

Description

@VHall1

Reproduction

vite.config.js

import { vitePlugin as remix } from "@remix-run/dev";
import { installGlobals } from "@remix-run/node";
import { defineConfig } from "vite";

installGlobals();

export default defineConfig({
  plugins: [remix()],
});

Step 1

.env

TEST_VARIABLE="test"

_index.js

export default function Index() {
  return <p>hello</p>;
}

export function loader() {
  console.log(process.env.TEST_VARIABLE);
}

Prints "test" on the server console.

Step 2

Change the variable value:

.env

TEST_VARIABLE="another test"

Vite will print the following in the console:

[vite] .env changed, restarting server...
[vite] server restarted.

The server restarts, but the loader still prints "test" rather than "another test".

System Info

System:
  OS: Windows 11 10.0.22631
  CPU: (16) x64 AMD Ryzen 7 5800X 8-Core Processor
  Memory: 22.05 GB / 31.92 GB
Binaries:
  Node: 20.9.0 - C:\Program Files\nodejs\node.EXE
  Yarn: 1.22.21 - ~\AppData\Roaming\npm\yarn.CMD
  npm: 10.2.5 - C:\Program Files\nodejs\npm.CMD
  pnpm: 8.11.0 - ~\AppData\Roaming\npm\pnpm.CMD
Browsers:
  Edge: Chromium (123.0.2420.97)
  Internet Explorer: 11.0.22621.3527
npmPackages:
  @remix-run/dev: ^2.9.2 => 2.9.2
  @remix-run/node: ^2.9.2 => 2.9.2
  @remix-run/react: ^2.9.2 => 2.9.2
  @remix-run/serve: ^2.9.2 => 2.9.2
  vite: ^5.1.0 => 5.2.11

Used Package Manager

npm

Expected Behavior

After changing the environment variable, the server should restart and the new value should be applied.

Actual Behavior

The server restarts, but the value doesn't actually change (only after the server is manually stopped/started).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions