Registry / web-framework / babel-plugin-bundled-import-meta

babel-plugin-bundled-import-meta

JSON →
library0.3.2jsnpmunverified

Babel plugin (v0.3.2, last updated 2020) that rewrites import.meta.url expressions to static file paths or runtime-resolved URLs for use in bundled JavaScript output. It allows developers to define mappings between local source directories and server URLs, and supports multiple import styles (amd, cjs, esm, iife, umd, system). Unlike alternatives like @rollup/plugin-replace or webpack's DefinePlugin, this plugin is specifically designed for bundlers like Rollup or custom Babel pipelines that need to preserve import.meta semantics in bundles. Requires @babel/core as a peer dependency. Active but low maintenance cadence.

npm install babel-plugin-bundled-import-meta
INSTALL
IMPORT
SIG · BABEL-PLUGIN-BUNDL
B
babel-plugin-bundled-import-meta
web-frameworkjavascriptv0.3.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 plugin
module.exports = ['bundled-import-meta', { mappings: { 'src': '/assets' } }];
const plugin = require('babel-plugin-bundled-import-meta').default;
The plugin is a CommonJS default export. Use string reference in Babel config.
ESM config usage
import bundledImportMeta from 'babel-plugin-bundled-import-meta'; export default { plugins: [[bundledImportMeta, { bundleDir: 'dist' }]] };
import { bundledImportMeta } from 'babel-plugin-bundled-import-meta';
Named export does not exist; must use default import for programmatic use.
Babel presets/plugins array
plugins: [['bundled-import-meta', { importStyle: 'esm' }]]
plugins: ['babel-plugin-bundled-import-meta']
String name should omit 'babel-plugin-' prefix; options object is optional but recommended.

Configures the plugin with mappings and bundleDir, showing how import.meta.url is rewritten for bundled output.

// babel.config.js module.exports = { plugins: [ ['bundled-import-meta', { mappings: { 'src/components': '/assets', 'node_modules': '/vendor' }, bundleDir: 'dist', importStyle: 'esm' }] ] }; // Before transformation: const url = import.meta.url; // After transformation (esm style): const url = new URL('/assets/components/my-file.js', import.meta.url).href; // If inside a mapped directory; otherwise falls back to bundleDir relative resolution.
Debug
Known issues
gotchaThe plugin does not support dynamic import.meta properties other than 'url'. Using import.meta.env or import.meta.hot will not be transformed and may cause runtime errors.
fix
Only use import.meta.url in your code; for other properties, use a different solution.
affects: >=0.0.0
gotchaWhen importStyle is set to 'esm', the generated code uses import.meta.url at runtime, which may fail in environments that don't support import.meta (e.g., older browsers or Node without --experimental-modules).
fix
Choose a different importStyle (e.g., 'cjs' or 'amd') that resolves the bundle URL via a different global or mechanism.
affects: >=0.0.0
deprecatedThe plugin relies on Greenkeeper badge and Travis CI, indicating maintenance may have stalled. No updates since 2020.
fix
Consider migrating to @rollup/plugin-replace or manual import.meta transformation for active support.
affects: >=0.0.0
gotchaIf no mapping matches the source file and bundleDir is not set correctly, the plugin throws an exception during build.
fix
Ensure all source files with import.meta.url are covered by mappings or reside under bundleDir.
affects: >=0.0.0
gotchaRelative URLs in mappings are resolved at runtime relative to the bundle URL; if the bundle URL is unknown, this can lead to incorrect absolute paths.
fix
Use absolute URLs in mappings when possible, or ensure bundle URL is known and static.
affects: >=0.0.0
Errors
Common errors & fixes
Error: Cannot find module 'babel-plugin-bundled-import-meta'
Plugin not installed or incorrectly referenced in Babel config.
fix
Run 'npm install babel-plugin-bundled-import-meta --save-dev' and use string 'bundled-import-meta' (without 'babel-plugin-' prefix).
TypeError: Cannot read property 'url' of undefined
import.meta is undefined in the runtime environment (e.g., Node.js without proper support).
fix
Set 'importStyle' to a non-'esm' value like 'cjs' to avoid relying on import.meta at runtime.
SyntaxError: Unexpected token .
Babel is not configured with the plugin, or the plugin is not applied before other transforms that parse import.meta.
fix
Ensure the plugin is listed in 'plugins' array, and check Babel version >= 7.7.0.
The plugin bundled-import-meta threw: Error: Could not resolve import.meta for file ...
Source file is outside any mapping and bundleDir, so plugin cannot determine a replacement.
fix
Add a mapping for the file's directory or set bundleDir to cover it.
Upgrade
Version history
0.3.2latest on npm
Audit
Dependencies
@babel/corerequiredRequired as a peer dependency; the plugin transforms AST via Babel's API.
Agent activity
13 hits · last 30 days
node
12
OpenAI (training)
1
Resources