Registry / devops / vite-plugin-meta-env

vite-plugin-meta-env

JSON →
library1.0.2jsnpmunverified

Vite plugin to expose dynamic or non-prefixed environment variables via import.meta.env. Current stable version 1.0.2 (Aug 2023). Allows defining variables not starting with VITE_ (the default envPrefix) or process.env. Configurable to attach variables to import.meta.env or process.env. Different from standard Vite env handling by enabling arbitrary variable names without prefix restrictions. Active maintenance with TypeScript types included. Minimal API with one function call.

npm install vite-plugin-meta-env
INSTALL
IMPORT
SIG · VITE-PLUGIN-META-E
V
vite-plugin-meta-env
devopsjavascriptv1.0.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

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

VitePluginMetaEnv
import VitePluginMetaEnv from 'vite-plugin-meta-env'
const { VitePluginMetaEnv } = require('vite-plugin-meta-env')
Plugin uses ESM default export; named import and CommonJS require will fail

Shows how to define custom env variables without VITE_ prefix and access them via import.meta.env.

// vite.config.ts import { defineConfig } from 'vite'; import vue from '@vitejs/plugin-vue'; import VitePluginMetaEnv from 'vite-plugin-meta-env'; export default defineConfig({ plugins: [ vue(), VitePluginMetaEnv({ APP_VERSION: '1.0.0', APP_BUILD_TIME: new Date().toISOString() }, 'import.meta.env') ] }); // In your code: console.log(import.meta.env.APP_VERSION); // '1.0.0'
Debug
Known issues
gotchaVariables defined with this plugin are statically embedded at build time. Changes to .env files or runtime environment after build will NOT be reflected.
fix
Rebuild the project after changing environment variable values. For dynamic runtime variables, use process.env with appropriate server-side handling.
affects: all
gotchaIf using TypeScript, you must manually extend ImportMetaEnv interface to get type safety and IntelliSense for custom variables.
fix
Add declarations in a .d.ts file per Vite docs: https://vitejs.dev/guide/env-and-mode.html#intellisense
affects: all
gotchaThe second parameter (defineOn) is not validated; passing an invalid value will silently fail (variables not exposed).
fix
Only use 'import.meta.env' or 'process.env' as the second argument. Check that variable is accessible after configuration.
affects: all
gotchaThis plugin only works during the Vite build process. It does not handle SSR or server-side runtime variables.
fix
For SSR, use Vite's define option or platform-specific runtime config. The plugin is intended for client-side builds only.
affects: all
Errors
Common errors & fixes
TypeError: VitePluginMetaEnv is not a function
Named import instead of default import (e.g., import { VitePluginMetaEnv } from 'vite-plugin-meta-env').
fix
Change to default import: import VitePluginMetaEnv from 'vite-plugin-meta-env'
Cannot read properties of undefined (reading 'APP_VERSION')
Variable not exposed because plugin not configured, or second argument misconfigured, or accessing before build.
fix
Ensure plugin is added to Vite plugins array with correct arguments. Access via import.meta.env only after build.
Module '"vite-plugin-meta-env"' has no exported member 'VitePluginMetaEnv'. Did you mean to use 'import VitePluginMetaEnv from "vite-plugin-meta-env"' instead?
Using named import when the package exports a default.
fix
Use default import syntax as shown in the docs.
Upgrade
Version history
1.0.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
OpenAI (training)
1
Resources
vite-plugin-meta-env — npm install vite-plugin-meta-env · libregistry