Registry / testing / babel-preset-vite

babel-preset-vite

JSON →
library1.1.3jsnpmunverified

A Babel preset that emulates Vite's non-standard functionality in non-Vite environments, primarily for testing with Node.js-based runners. Version 1.1.3 (stable) includes three plugins: babel-plugin-transform-vite-meta-env (import.meta.env), babel-plugin-transform-vite-meta-glob (import.meta.glob), and babel-plugin-transform-vite-meta-hot (import.meta.hot). Each plugin can be individually disabled via preset options. The preset ships TypeScript types and follows a monthly release cadence with bug fixes. Key differentiator: allows code using Vite-specific features to run in Jest or other Node.js test runners without modification.

npm install babel-preset-vite
INSTALL
IMPORT
SIG · BABEL-PRESET-VITE
B
babel-preset-vite
testingjavascriptv1.1.3
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 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

default
module.exports = require('babel-preset-vite')
import preset from 'babel-preset-vite'
Preset is CommonJS-only; no default ESM export.
babel-preset-vite
{ "presets": ["babel-preset-vite"] }
{ "presets": ["babel-preset-vite", {}] }
Options object is the second element of a tuple, not standalone.
env option
{ "presets": [["babel-preset-vite", { "env": false }]] }
{ "presets": ["babel-preset-vite", { "env": false }] }
Options must be inside an array element: ["preset-name", options].

Shows installation, configuration with options, and example Vite features transformed by the preset.

// Install npm install --save-dev babel-preset-vite // Configure (babel.config.js) module.exports = { presets: [ ['babel-preset-vite', { env: true, glob: true, hot: true }] ] }; // Example code that uses Vite features const env = import.meta.env.VITE_API_URL; const modules = import.meta.glob('./modules/*.js'); // After Babel transformation, above will be replaced with actual values or stubs.
Debug
Known issues
gotchaPreset is intended for testing only; should not be relied upon in production.
fix
Only use in development/test environments.
affects: >=0.0.0
breakingv1.1.0 introduced import.meta.hot support. Older versions (<=1.0.4) do not transform import.meta.hot.
fix
Upgrade to >=1.1.0 if you need HMR stubs.
affects: <=1.0.4
deprecatedimport.meta.globEager is deprecated in Vite 5; use import.meta.glob with { eager: true } instead.
fix
Switch to import.meta.glob('./*.js', { eager: true }).
affects: >=1.0.0
gotchaWindows path separator backslash may be replaced with forward slash (fixed in 1.1.2).
fix
Upgrade to >=1.1.2.
affects: <1.1.2
gotchaUnknown import.meta.env keys are replaced with the full env object instead of undefined (fixed in 1.0.3).
fix
Upgrade to >=1.0.3.
affects: <1.0.3
Errors
Common errors & fixes
TypeError: Cannot read property 'env' of undefined
Preset options not wrapped in an array tuple.
fix
Use [["babel-preset-vite", { "env": true }]] instead of ["babel-preset-vite", { "env": true }].
Module not found: Can't resolve 'babel-plugin-transform-vite-meta-env'
Missing dependency; npm did not install all plugins.
fix
Run npm install to ensure all dependencies are installed.
Error: Plugin/Preset files are not allowed to export objects, only functions.
Using ES module import with a CJS-only preset.
fix
Use require() or set type: 'commonjs' in babel.config.
ReferenceError: import.meta is not defined
Preset is not applied; Babel is not configured correctly.
fix
Add 'babel-preset-vite' to presets in babel.config.js or .babelrc.
Upgrade
Version history
1.1.3latest on npm
Audit
Dependencies
@babel/corerequiredPeer dependency for Babel transformations.
babel-plugin-transform-vite-meta-envrequiredTransforms import.meta.env.
babel-plugin-transform-vite-meta-globrequiredTransforms import.meta.glob.
babel-plugin-transform-vite-meta-hotrequiredTransforms import.meta.hot.
Agent activity
20 hits · last 30 days
node
18
OpenAI (training)
1
Resources
babel-preset-vite — npm install babel-preset-vite · libregistry