Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–223 runs
build_error
glibcnode 18–223 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
loadEnv
✓ import { loadEnv } from 'vite-plugin-watch-env'
✗ import loadEnv from 'vite-plugin-watch-env'
loadEnv is a named export, not default. CommonJS: const { loadEnv } = require('vite-plugin-watch-env')
watchEnv
✓ import { watchEnv } from 'vite-plugin-watch-env'
✗ const watchEnv = require('vite-plugin-watch-env').watchEnv
watchEnv is a named export. Ensure to call it as a function in the plugins array.
default import
✓ import vitePluginWatchEnv from 'vite-plugin-watch-env'
✗ import { default } from 'vite-plugin-watch-env'
Package has a default export that is an object? Actually there is no default export. Use named exports.
type imports
✓ import type { WatchEnvOptions } from 'vite-plugin-watch-env'
✗ import { WatchEnvOptions } from 'vite-plugin-watch-env'
If types are exported, use type import to avoid bundling
Loads env file and watches for changes; exposes env to client via define.
import { defineConfig } from 'vite';
import { loadEnv, watchEnv } from 'vite-plugin-watch-env';
export default ({ mode }: { mode: string }) => {
loadEnv(`./.env.${mode}`);
return defineConfig({
plugins: [watchEnv()],
define: {
'process.env': {
TEST_ENV_VALUE: process.env.TEST_ENV_VALUE,
},
},
});
};
Errors
Common errors & fixes
Cannot find module 'vite-plugin-watch-env'
Package not installed or not in devDependencies
fixRun npm install vite-plugin-watch-env --save-dev
TypeError: loadEnv is not a function
Import from wrong path or default import instead of named
fixUse import { loadEnv } from 'vite-plugin-watch-env' Error: The file '.env.development' does not exist
File path passed to loadEnv is incorrect or file missing
fixEnsure the path is relative to project root or absolute, and file exists
Audit
Dependencies
viterequiredPeer dependency; plugin designed for Vite