Babel plugin that emulates Vite's import.meta.env functionality for non-Vite environments, such as testing with NodeJS-based runners. Version 1.0.3 is the latest stable release, last updated in April 2021. It transforms import.meta.env.MODE, .BASE_URL, .DEV, .PROD, etc. into process.env references or static values, providing an approximation of Vite's env behavior. Differentiated from alternatives like @rollup/plugin-replace by specifically targeting Vite idioms and supporting a set of predefined env variables. Release cadence is low; part of the babel-vite monorepo. Ships TypeScript types.
npm install babel-plugin-transform-vite-meta-envVerified import paths — ran on the pinned version, not inferred.
Configures Babel to replace import.meta.env references with process.env equivalents or static values, useful for testing Vite-dependent code in non-Vite environments.
Set NODE_ENV explicitly to 'production' or 'development' before running tests.
Define all used env variables in your Vite config and ensure they are prefixed with VITE_, or handle undefined cases in code.
Migrate tests to Vitest, which natively resolves import.meta.env.
Set NODE_ENV explicitly in test scripts (e.g., "test": "NODE_ENV=test jest").
Run 'npm install --save-dev babel-plugin-transform-vite-meta-env' and ensure it's in package.json devDependencies.
Verify Babel configuration includes the plugin and that you are transforming the file (e.g., using @babel/register or build step).
Ensure Babel runs on the file and the plugin is active. For Node.js <14, upgrade or use @babel/plugin-syntax-import-meta.
No dependency data recorded yet.