-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Changing environment variables restarts Vite server but doesn't actually update value #9587
Comments
Think I might have figured out why. It seems like the Remix plugin is loading Remix Plugin remix/packages/remix-dev/vite/plugin.ts Line 1019 in c3efad3
|
@VHall1 I just found a way to resolve it, but I still hope Remix official team to fix it. import { vitePlugin as remix } from '@remix-run/dev';
import { defineConfig, loadEnv } from 'vite';
import tsconfigPaths from 'vite-tsconfig-paths';
export default defineConfig(({ mode }) => {
// Load environment variables based on the mode (e.g. development, production)
const env = loadEnv(mode, process.cwd(), '');
return {
server: {
host: '127.0.0.1',
port: Number(env.PORT) || 3000,
strictPort: true
},
plugins: [
remix({
future: {
v3_fetcherPersist: true,
v3_relativeSplatPath: true,
v3_throwAbortReason: true
},
serverModuleFormat: 'esm'
}),
tsconfigPaths()
]
};
}); Project Information
By doing this, we explicitly load the environment variables using Vite's Hope this helps, and I look forward to an official fix from the Remix team! |
Reproduction
vite.config.js
Step 1
.env
_index.js
Prints "test" on the server console.
Step 2
Change the variable value:
.env
Vite will print the following in the console:
The server restarts, but the loader still prints "test" rather than "another test".
System Info
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).
The text was updated successfully, but these errors were encountered: