Registry / devops / vite-plugin-runtime-dotenv

vite-plugin-runtime-dotenv

JSON →
library1.0.0jsnpmunverified

A Vite plugin that enables runtime environment variables, allowing a single build to be deployed across multiple environments by generating separate builds with environment-specific variables injected. Version 1.0.0 requires Vite 7.x and ships TypeScript type definitions. Released in 2025. Unlike compile-time env substitution, this plugin duplicates the output into per-mode directories with injected runtime variables, making it suitable for CI/CD workflows where you want to 'build once, deploy anywhere'.

npm install vite-plugin-runtime-dotenv
INSTALL
IMPORT
SIG · VITE-PLUGIN-RUNTIM
V
vite-plugin-runtime-dotenv
devopsjavascriptv1.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

runtimeEnv
✓ import { runtimeEnv } from 'vite-plugin-runtime-dotenv'
✗ import runtimeEnv from 'vite-plugin-runtime-dotenv'
Named export only; default import does not exist and will be undefined.
RuntimeEnvOptions
✓ import type { RuntimeEnvOptions } from 'vite-plugin-runtime-dotenv'
✗ import { RuntimeEnvOptions } from 'vite-plugin-runtime-dotenv'
This is a TypeScript type export, not a runtime value. Use 'import type'.
plugin (require)
✓ const { runtimeEnv } = require('vite-plugin-runtime-dotenv')
✗ const runtimeEnv = require('vite-plugin-runtime-dotenv')
CJS require destructures the named export; default require returns the module object.

Configures the plugin with three modes, enables TypeScript declaration generation, and shows how to access variables in application code.

// vite.config.ts import { defineConfig } from 'vite'; import { runtimeEnv } from 'vite-plugin-runtime-dotenv'; export default defineConfig({ plugins: [ runtimeEnv({ output: 'runtimeEnv.js', globalVariableName: 'runtimeEnv', modes: ['qa', 'stg', 'prod'], generateDts: true, defaultEnvFilenameAliases: { production: 'prod', development: 'dev', }, }), ], }); // In your app code, access env variables via globalThis.runtimeEnv.VITE_API_URL
Debug
Known issues
breakingRequires Vite ^7.0.0 – incompatible with older Vite versions
fix
Upgrade Vite to version 7 or higher, or use an alternative plugin for older Vite.
affects: <7.0.0
gotchaThe 'modes' array is required – omitting it causes a runtime error
fix
Provide at least one mode in the 'modes' array.
affects: >=1.0.0
gotchaOnly variables that start with VITE_ (or custom prefix if configured) are exposed to client code
fix
Prefix your environment variables with VITE_ or configure the 'envPrefix' option in Vite.
affects: >=1.0.0
gotchaThe generated runtimeEnv.js is placed in each mode's output directory, not at the root of dist
fix
Ensure your deployment script references the correct path, e.g., dist/qa/runtimeEnv.js.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Cannot destructure property 'runtimeEnv' of '...' as it is undefined
Default import used instead of named import
fix
import { runtimeEnv } from 'vite-plugin-runtime-dotenv'
The plugin requires at least one mode to be provided
The 'modes' option was omitted or set to an empty array
fix
Add a non-empty 'modes' array to the plugin options.
Error: Cannot find module 'vite-plugin-runtime-dotenv'
Package not installed or peer dependency Vite ^7.0.0 not met
fix
Run 'npm install vite-plugin-runtime-dotenv' and ensure Vite version is >=7.0.0
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
viterequiredpeer dependency – plugin requires Vite ^7.0.0 to function
Agent activity
2 hits · last 30 days
node
2
Resources
vite-plugin-runtime-dotenv — npm install vite-plugin-runtime-dotenv · libregistry