{"id":22924,"library":"vite-plugin-watch-env","title":"Vite Plugin Watch Env","description":"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.","status":"active","version":"1.0.1","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/Enoooch/vite-plugin-watch-env","tags":["javascript","vite-plugin","watch-env","dot-env","env","typescript"],"install":[{"cmd":"npm install vite-plugin-watch-env","lang":"bash","label":"npm"},{"cmd":"yarn add vite-plugin-watch-env","lang":"bash","label":"yarn"},{"cmd":"pnpm add vite-plugin-watch-env","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency; plugin designed for Vite","package":"vite","optional":false}],"imports":[{"note":"loadEnv is a named export, not default. CommonJS: const { loadEnv } = require('vite-plugin-watch-env')","wrong":"import loadEnv from 'vite-plugin-watch-env'","symbol":"loadEnv","correct":"import { loadEnv } from 'vite-plugin-watch-env'"},{"note":"watchEnv is a named export. Ensure to call it as a function in the plugins array.","wrong":"const watchEnv = require('vite-plugin-watch-env').watchEnv","symbol":"watchEnv","correct":"import { watchEnv } from 'vite-plugin-watch-env'"},{"note":"Package has a default export that is an object? Actually there is no default export. Use named exports.","wrong":"import { default } from 'vite-plugin-watch-env'","symbol":"default import","correct":"import vitePluginWatchEnv from 'vite-plugin-watch-env'"},{"note":"If types are exported, use type import to avoid bundling","wrong":"import { WatchEnvOptions } from 'vite-plugin-watch-env'","symbol":"type imports","correct":"import type { WatchEnvOptions } from 'vite-plugin-watch-env'"}],"quickstart":{"code":"import { defineConfig } from 'vite';\nimport { loadEnv, watchEnv } from 'vite-plugin-watch-env';\n\nexport default ({ mode }: { mode: string }) => {\n  loadEnv(`./.env.${mode}`);\n  return defineConfig({\n    plugins: [watchEnv()],\n    define: {\n      'process.env': {\n        TEST_ENV_VALUE: process.env.TEST_ENV_VALUE,\n      },\n    },\n  });\n};","lang":"typescript","description":"Loads env file and watches for changes; exposes env to client via define."},"warnings":[{"fix":"Ensure to call loadEnv before any other env reads, or manually merge with Object.assign(process.env, loaded)","message":"loadEnv does not merge with existing process.env – it overrides","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Call loadEnv for each .env file you want to watch","message":"watchEnv only watches the path passed to loadEnv; changes to other .env files not watched","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"For static env without watching, use Vite's loadEnv from 'vite' instead","message":"The package has no deprecation warnings, but few releases; consider using vite's built-in loadEnv for static env","severity":"deprecated","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Run npm install vite-plugin-watch-env --save-dev","cause":"Package not installed or not in devDependencies","error":"Cannot find module 'vite-plugin-watch-env'"},{"fix":"Use import { loadEnv } from 'vite-plugin-watch-env'","cause":"Import from wrong path or default import instead of named","error":"TypeError: loadEnv is not a function"},{"fix":"Ensure the path is relative to project root or absolute, and file exists","cause":"File path passed to loadEnv is incorrect or file missing","error":"Error: The file '.env.development' does not exist"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}