Registry / testing / babel-plugin-transform-vite-meta-glob

babel-plugin-transform-vite-meta-glob

JSON →
library1.1.2jsnpmunverified

Babel plugin that emulates Vite's import.meta.glob and import.meta.globEager functionality for use in non-Vite environments like Node.js test runners. Version 1.1.2 is current, released January 2024. Regularly updated with bug fixes and feature support, including eager imports via options. It provides an approximation of Vite's glob import transformation, not for production use. Differentiates from Vite itself by enabling these features in plain Babel pipelines, often used with Jest or Mocha.

npm install babel-plugin-transform-vite-meta-glob
INSTALL
IMPORT
SIG · BABEL-PLUGIN-TRANS
B
babel-plugin-transform-vite-meta-glob
testingjavascriptv1.1.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 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

default
import plugin from 'babel-plugin-transform-vite-meta-glob'
const plugin = require('babel-plugin-transform-vite-meta-glob')
ESM default export since v1. For CJS, use default import via babel.config.js or dynamic require()
plugin as function
plugins: ['babel-plugin-transform-vite-meta-glob']
plugins: [require('babel-plugin-transform-vite-meta-glob')]
String syntax in Babel config is preferred; direct require works but may cause issues with module resolution
TypeScript types
import type { PluginObj } from '@babel/core'
This package includes TypeScript definitions; import plugin as shown above and assign to variable with type PluginObj

Shows Babel config setup and glob import transformation output with dynamic imports.

// babel.config.js module.exports = { plugins: [ 'babel-plugin-transform-vite-meta-glob' ] }; // src/modules.js const modules = import.meta.glob('./fixtures/*.js'); // After transformation, modules becomes: // { // './fixtures/a.js': () => import('./fixtures/a.js'), // './fixtures/b.js': () => import('./fixtures/b.js') // } export default modules;
Debug
Known issues
gotchaOn Windows, generated paths use backslashes, causing issues. Fixed in 1.1.2, but ensure you have at least that version.
fix
Update to v1.1.2+ or manually replace backslashes in glob patterns.
affects: <1.1.2
deprecatedimport.meta.globEager is deprecated; use import.meta.glob with '{ eager: true }' instead.
fix
Replace import.meta.globEager('./path') with import.meta.glob('./path', { eager: true })
affects: >=1.1.0
gotchaThe plugin only transforms static glob patterns; dynamic expressions like import.meta.glob(someVar) are left untouched.
fix
Use a static string literal for the glob pattern.
affects: >=1.0.0
gotchaEager imports with { eager: true } require a supporting Babel version that understands import() statements; ensure @babel/core is up to date.
fix
Install @babel/core@^7.0.0 and @babel/plugin-syntax-dynamic-import if needed.
affects: >=1.1.0
deprecatedThe plugin uses __glob__* variable naming, which may conflict with user code. No change planned.
fix
Avoid using __glob__ prefixed variables in your code.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'babel-plugin-transform-vite-meta-glob'
Plugin not installed or Babel is looking in wrong node_modules.
fix
Run npm install --save-dev babel-plugin-transform-vite-meta-glob and ensure Babel's config resolves from your project root.
TypeError: (0 , _default.default) is not a function
Using CJS require() to import the ESM default export incorrectly.
fix
Use string reference in Babel config: plugins: ['babel-plugin-transform-vite-meta-glob'] instead of requiring directly.
SyntaxError: Unexpected token 'import'
Babel is not configured to handle dynamic import() syntax.
fix
Install @babel/plugin-syntax-dynamic-import and add it to your plugins array.
Error: .globEager is not a function
Using deprecated import.meta.globEager with a plugin version that doesn't support it yet.
fix
Use import.meta.glob with { eager: true } option, or update the plugin to v1.1.0+.
Error: Could not resolve glob pattern 'C:\path'
Windows backslashes in glob pattern not normalized; affected versions <1.1.2.
fix
Update to v1.1.2+ or use forward slashes in glob patterns.
Upgrade
Version history
1.1.2latest on npm
Audit
Dependencies
babel-plugin-transform-vite-meta-envoptionaloften used together in babel-preset-vite; not required standalone
Agent activity
20 hits · last 30 days
node
16
OpenAI (training)
2
Resources
babel-plugin-transform-vite-meta-glob — npm install babel-plugin-transform-vite-meta-glob · libregistry