Registry / devops / vite-plugin-watch-env

vite-plugin-watch-env

JSON →
library1.0.1jsnpmunverified

A Vite plugin that loads .env files into process.env and watches for file changes to automatically reload the environment. v1.0.1 is current stable. It provides two functions: loadEnv to load a .env file synchronously at config time, and watchEnv to add the Vite plugin that triggers re-serve when the .env file changes. Lightweight, TypeScript-ready, alternative to dotenv for Vite projects that need hot-reload on env changes.

npm install vite-plugin-watch-env
INSTALL
IMPORT
SIG · VITE-PLUGIN-WATCH-
V
vite-plugin-watch-env
devopsjavascriptv1.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
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
musl
node 18223 runs
build_error
glibc
node 18223 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, }, }, }); };
Debug
Known issues
gotchaloadEnv does not merge with existing process.env – it overrides
fix
Ensure to call loadEnv before any other env reads, or manually merge with Object.assign(process.env, loaded)
affects: >=1.0.0
gotchawatchEnv only watches the path passed to loadEnv; changes to other .env files not watched
fix
Call loadEnv for each .env file you want to watch
affects: >=1.0.0
deprecatedThe package has no deprecation warnings, but few releases; consider using vite's built-in loadEnv for static env
fix
For static env without watching, use Vite's loadEnv from 'vite' instead
affects: *
Errors
Common errors & fixes
Cannot find module 'vite-plugin-watch-env'
Package not installed or not in devDependencies
fix
Run npm install vite-plugin-watch-env --save-dev
TypeError: loadEnv is not a function
Import from wrong path or default import instead of named
fix
Use 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
fix
Ensure the path is relative to project root or absolute, and file exists
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies
viterequiredPeer dependency; plugin designed for Vite
Agent activity
8 hits · last 30 days
node
6
OpenAI (training)
2
Resources
vite-plugin-watch-env — npm install vite-plugin-watch-env · libregistry