{"id":19029,"library":"babel-plugin-bundled-import-meta","title":"babel-plugin-bundled-import-meta","description":"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.","status":"active","version":"0.3.2","language":"javascript","source_language":"en","source_url":"https://github.com/cfware/babel-plugin-bundled-import-meta","tags":["javascript","babel","esm","browser","import.meta.url","rollup"],"install":[{"cmd":"npm install babel-plugin-bundled-import-meta","lang":"bash","label":"npm"},{"cmd":"yarn add babel-plugin-bundled-import-meta","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-plugin-bundled-import-meta","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required as a peer dependency; the plugin transforms AST via Babel's API.","package":"@babel/core","optional":false}],"imports":[{"note":"The plugin is a CommonJS default export. Use string reference in Babel config.","wrong":"const plugin = require('babel-plugin-bundled-import-meta').default;","symbol":"default plugin","correct":"module.exports = ['bundled-import-meta', { mappings: { 'src': '/assets' } }];"},{"note":"Named export does not exist; must use default import for programmatic use.","wrong":"import { bundledImportMeta } from 'babel-plugin-bundled-import-meta';","symbol":"ESM config usage","correct":"import bundledImportMeta from 'babel-plugin-bundled-import-meta'; export default { plugins: [[bundledImportMeta, { bundleDir: 'dist' }]] };"},{"note":"String name should omit 'babel-plugin-' prefix; options object is optional but recommended.","wrong":"plugins: ['babel-plugin-bundled-import-meta']","symbol":"Babel presets/plugins array","correct":"plugins: [['bundled-import-meta', { importStyle: 'esm' }]]"}],"quickstart":{"code":"// babel.config.js\nmodule.exports = {\n  plugins: [\n    ['bundled-import-meta', {\n      mappings: {\n        'src/components': '/assets',\n        'node_modules': '/vendor'\n      },\n      bundleDir: 'dist',\n      importStyle: 'esm'\n    }]\n  ]\n};\n\n// Before transformation:\nconst url = import.meta.url;\n\n// After transformation (esm style):\nconst url = new URL('/assets/components/my-file.js', import.meta.url).href;\n// If inside a mapped directory; otherwise falls back to bundleDir relative resolution.\n","lang":"javascript","description":"Configures the plugin with mappings and bundleDir, showing how import.meta.url is rewritten for bundled output."},"warnings":[{"fix":"Only use import.meta.url in your code; for other properties, use a different solution.","message":"The 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.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Choose a different importStyle (e.g., 'cjs' or 'amd') that resolves the bundle URL via a different global or mechanism.","message":"When 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).","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Consider migrating to @rollup/plugin-replace or manual import.meta transformation for active support.","message":"The plugin relies on Greenkeeper badge and Travis CI, indicating maintenance may have stalled. No updates since 2020.","severity":"deprecated","affected_versions":">=0.0.0"},{"fix":"Ensure all source files with import.meta.url are covered by mappings or reside under bundleDir.","message":"If no mapping matches the source file and bundleDir is not set correctly, the plugin throws an exception during build.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use absolute URLs in mappings when possible, or ensure bundle URL is known and static.","message":"Relative 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.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run 'npm install babel-plugin-bundled-import-meta --save-dev' and use string 'bundled-import-meta' (without 'babel-plugin-' prefix).","cause":"Plugin not installed or incorrectly referenced in Babel config.","error":"Error: Cannot find module 'babel-plugin-bundled-import-meta'"},{"fix":"Set 'importStyle' to a non-'esm' value like 'cjs' to avoid relying on import.meta at runtime.","cause":"import.meta is undefined in the runtime environment (e.g., Node.js without proper support).","error":"TypeError: Cannot read property 'url' of undefined"},{"fix":"Ensure the plugin is listed in 'plugins' array, and check Babel version >= 7.7.0.","cause":"Babel is not configured with the plugin, or the plugin is not applied before other transforms that parse import.meta.","error":"SyntaxError: Unexpected token ."},{"fix":"Add a mapping for the file's directory or set bundleDir to cover it.","cause":"Source file is outside any mapping and bundleDir, so plugin cannot determine a replacement.","error":"The plugin bundled-import-meta threw: Error: Could not resolve import.meta for file ..."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}