{"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,"search_vec":"'1.4.0':26 '18':67 '2024':28 'activ':31 'ad':40 'build':14 'current':22 'depend':74 'differenti':47 'elimin':48 'env.js':55 'environ':19 'envsubsttempl':43 'everi':37 'featur':41 'file':56 'flex':81 'flexbas':80 'flexibl':17 'generat':53,59 'html':63 'import.meta.env.vite':10 'inject':21,62 'injecthtml':45 'javascript':79 'juli':27 'key':46 'like':42 'minor/patch':35 'month':39 'new':34 'node':66 'peer':73 'plugin':3,7,85 'prefix':51 'releas':29 'replac':9 'requir':52,65,78 'runtim':4,18,54 'script':64 'stabl':23 'support':57 'time':15 'type':58 'variabl':20 'version':24,36,70 'vite':2,6,50,72,76,82,84 'vite-plugin':83 'vite-plugin-runtim':1 'window.env':12","created_at":"2026-04-27T17:07:15.708296+00:00","updated_at":"2026-04-27T17:07:15.708296+00:00","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,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/flexbase-eng/vite-plugin-runtime","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/vite-plugin-runtime","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops","web-framework"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-18","next_check":"2026-07-26","install_tag":null}}