{"id":22823,"library":"vite-plugin-runtime","title":"vite-plugin-runtime","description":"A Vite plugin that replaces `import.meta.env.VITE_*` with `window.env.*` at build time for flexible runtime environment variable injection. Current stable version is 1.4.0 (July 2024). Releases are active with a new minor/patch version every few months, adding features like `envsubstTemplate` and `injectHtml`. Key differentiators: eliminates the VITE_ prefix requirement, generates runtime env.js files, supports type generation, and can inject HTML scripts. Requires Node >=18 and any version of Vite. Peer dependency on Vite is required.","status":"active","version":"1.4.0","language":"javascript","source_language":"en","source_url":"https://github.com/flexbase-eng/vite-plugin-runtime","tags":["javascript","flexbase","flex","vite","vite-plugin"],"install":[{"cmd":"npm install vite-plugin-runtime","lang":"bash","label":"npm"},{"cmd":"yarn add vite-plugin-runtime","lang":"bash","label":"yarn"},{"cmd":"pnpm add vite-plugin-runtime","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required as a peer dependency; the plugin hooks into Vite's build process.","package":"vite","optional":false}],"imports":[{"note":"Named export, not default. The function is named `runtimeEnv`, not `runtime`.","wrong":"import runtimeEnv from 'vite-plugin-runtime'","symbol":"runtimeEnv","correct":"import { runtimeEnv } from 'vite-plugin-runtime'"},{"note":"ESM-only. CommonJS require is not supported.","wrong":"const { runtimeHtml } = require('vite-plugin-runtime')","symbol":"runtimeHtml","correct":"import { runtimeHtml } from 'vite-plugin-runtime'"},{"note":"Options type is exported as a type, not a value. Use `import type` in TypeScript.","wrong":"import { VitePluginRuntimeOptions } from 'vite-plugin-runtime'","symbol":"VitePluginRuntime (type)","correct":"import type { VitePluginRuntimeOptions } from 'vite-plugin-runtime'"}],"quickstart":{"code":"// vite.config.ts\nimport { defineConfig } from 'vite';\nimport { runtimeEnv } from 'vite-plugin-runtime';\n\nexport default defineConfig({\n  plugins: [\n    runtimeEnv({\n      name: 'env',\n      injectHtml: true,\n      generateTypes: true,\n      generatedTypesPath: () => './src',\n      envsubstTemplate: false,\n    }),\n  ],\n});","lang":"typescript","description":"Configures vite-plugin-runtime with the runtimeEnv plugin, setting the runtime object name to 'env', enabling HTML injection and type generation."},"warnings":[{"fix":"Upgrade Node to version 18 or higher.","message":"Requires Node >=18; older Node versions will fail at install.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Use ESM imports: `import { runtimeEnv } from 'vite-plugin-runtime'`.","message":"The plugin only works in ESM environments; CommonJS import (require) will throw an error.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Either leave `injectHtml: true` or add a `<script>` tag loading `/env.js` in your HTML file.","message":"If `injectHtml` is false, you must manually include `/env.js` or the runtime variables will not be available.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Update your code to use `window.env.VARIABLE` or set a custom `name` option.","message":"The default `name` is `env`, so runtime variables are accessed as `window.env.VARIABLE` instead of `import.meta.env.VITE_VARIABLE`.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Only enable `envsubstTemplate` if you specifically need to create an envsubst template file.","message":"The `envsubstTemplate` option defaults to `false` and is not intended for production use; it's for generating a template for environment variable substitution.","severity":"deprecated","affected_versions":">=1.4.0"},{"fix":"Use only one runtimeEnv plugin instance, or ensure plugin ordering is correct.","message":"If you have multiple runtimeEnv plugin instances with different names, the last one's configuration may override previous ones due to Vite plugin order.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Change to `import { runtimeEnv } from 'vite-plugin-runtime'`.","cause":"Using a default import instead of a named import.","error":"Error: 'runtimeEnv' is not exported from 'vite-plugin-runtime'"},{"fix":"Switch to ESM imports or use a dynamic import: `const { runtimeEnv } = await import('vite-plugin-runtime')`.","cause":"Trying to use CommonJS require with this ESM-only package.","error":"TypeError: require(...) is not a function"},{"fix":"Run `npm install --save-dev vite vite-plugin-runtime`.","cause":"Missing peer dependency 'vite' or not installed as devDependency.","error":"Cannot find module 'vite-plugin-runtime' or its corresponding type declarations."},{"fix":"Set `injectHtml: true` or manually include `<script src='/env.js'></script>` in your HTML file.","cause":"The `injectHtml` option is set to `false` and the env.js script is not manually loaded.","error":"Window.env is undefined at runtime"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}