{"id":22650,"library":"vite-plugin-env","title":"vite-plugin-env","description":"A Vite plugin that injects custom environment variables into the client bundle via import.meta.env. Current stable version is 1.0.1, released with no documented release cadence. It differentiates from Vite's built-in env handling by allowing custom variables defined directly in the Vite config, rather than relying on .env files or process.env. Supports TypeScript types but its API surface is minimal. Caution: The README example contains a typo referencing 'vite-plugin-stachtml' which will cause import errors.","status":"active","version":"1.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/zouloux/deuspi","tags":["javascript","vite","plugin","custom","env","envs","variable","typescript"],"install":[{"cmd":"npm install vite-plugin-env","lang":"bash","label":"npm"},{"cmd":"yarn add vite-plugin-env","lang":"bash","label":"yarn"},{"cmd":"pnpm add vite-plugin-env","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Named export only. Default import will fail.","wrong":"import env from 'vite-plugin-env'","symbol":"env","correct":"import { env } from 'vite-plugin-env'"},{"note":"CommonJS require using destructuring. The plugin is ESM-first but works with CJS via dynamic require.","wrong":"const vitePluginEnv = require('vite-plugin-env')","symbol":"vite-plugin-env (package)","correct":"const { env } = require('vite-plugin-env')"},{"note":"TypeScript users may want to type the plugin return value as Plugin, but vite-plugin-env does not export a Plugin type directly.","wrong":"import { env } from 'vite-plugin-env' // no type import","symbol":"Plugin type","correct":"import type { Plugin } from 'vite'; import { env } from 'vite-plugin-env'"}],"quickstart":{"code":"// vite.config.ts\nimport { defineConfig } from 'vite';\nimport { env } from 'vite-plugin-env';\n\nexport default defineConfig({\n  plugins: [\n    env({\n      MY_CUSTOM_ENV: 'Hello from vite config',\n      YOUR_SECRET_KEY: process.env.YOUR_SECRET_KEY ?? ''\n    })\n  ]\n});\n\n// src/index.ts\nconsole.log(import.meta.env.MY_CUSTOM_ENV); // 'Hello from vite config'\nconsole.log(import.meta.env.YOUR_SECRET_KEY); // value of env var or ''","lang":"typescript","description":"Shows how to use the env plugin to inject custom variables into import.meta.env, including a fallback for secrets via process.env."},"warnings":[{"fix":"Replace import { env } from 'vite-plugin-stachtml' with import { env } from 'vite-plugin-env'.","message":"The README example mistakenly imports from 'vite-plugin-stachtml' instead of 'vite-plugin-env'.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Ensure env({ ... }) returns a valid Vite plugin object.","message":"The env function must be called as a function, not used as an object. Misuse will cause Vite to throw Plugin type error.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Use process.env for server-side variables or define plugin for universal values.","message":"Variables set via env plugin are only available in client code, not in Node.js environment (e.g., vite.config.ts itself).","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use uppercase variable names (e.g., MY_VAR).","message":"Variable names must be uppercase or Vite may strip them due to security filters on import.meta.env.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'1.0.1':23 'allow':41 'api':63 'built':36 'built-in':35 'bundl':16 'cadenc':29 'caus':81 'caution':67 'client':15 'config':49 'contain':71 'current':19 'custom':10,42,87 'defin':44 'differenti':31 'direct':45 'document':27 'env':4,38,54,88,89 'environ':11 'error':83 'exampl':70 'file':55 'handl':39 'import':82 'import.meta.env':18 'inject':9 'javascript':84 'minim':66 'plugin':3,7,77,86 'process.env':57 'rather':50 'readm':69 'referenc':74 'releas':24,28 'reli':52 'stabl':20 'stachtml':78 'support':58 'surfac':64 'type':60 'typescript':59,91 'typo':73 'variabl':12,43,90 'version':21 'via':17 'vite':2,6,33,48,76,85 'vite-plugin-env':1 'vite-plugin-stachtml':75","created_at":"2026-04-27T17:06:17.952472+00:00","updated_at":"2026-04-27T17:06:17.952472+00:00","problems":[{"fix":"Ensure you call env({ ... }) and import { env } from 'vite-plugin-env'.","cause":"env() not called as a function or imported incorrectly.","error":"MissingPluginError: The plugin 'env' was not found or has invalid shape."},{"fix":"Add MY_VAR to the env({...}) object with a default value.","cause":"Variable not defined in env plugin config.","error":"[vite] Internal server error: import.meta.env.MY_VAR is undefined"},{"fix":"Run npm install vite-plugin-env --save-dev","cause":"Package not installed.","error":"Error: Cannot find module 'vite-plugin-env'"}],"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/zouloux/deuspi","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/vite-plugin-env","openapi_spec":null,"status_page":null,"smithery":null,"categories":["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}}