Registry / devops / babel-plugin-import-map

babel-plugin-import-map

JSON →
library1.0.0jsnpmunverified

A Babel plugin to apply import map mappings to ECMAScript modules ahead of time. Current stable version is 1.0.0. This plugin allows transforming bare import specifiers (e.g., 'lit-html') to absolute URLs (e.g., CDN URLs) at build time, based on one or more import map files. It supports loading import maps from JSON files or plain objects, and can merge multiple maps. Unlike runtime import map polyfills, this works purely at the build level, making it suitable for production bundles. Once loaded, the plugin replaces import specifiers statically during Babel transpilation.

npm install babel-plugin-import-map
INSTALL
IMPORT
SIG · BABEL-PLUGIN-IMPOR
B
babel-plugin-import-map
devopsjavascriptv1.0.0
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.

plugin
import * as plugin from 'babel-plugin-import-map'
import plugin from 'babel-plugin-import-map'
This package uses a namespace import; default import does not work.
plugin.load()
plugin.load('./import-map.json')
plugin.load({imports: {'lit-html': 'https://cdn.example.com/lit-html.js'}})
You can pass a string path or an object; wrong example is actually correct, but a common mistake is to forget the './' relative path.
plugin.plugin()
plugin.plugin()
plugin()
The plugin function is a method on the imported namespace, not the default export itself.
plugin.clear()
plugin.clear()
plugin.clear
clear() is a method that must be called; omitting parentheses is a common mistake.

Shows how to load an import map file and apply the plugin in a Babel configuration to transform bare ESM imports.

import * as plugin from 'babel-plugin-import-map'; plugin.load('import-map.json'); export default { presets: [ ['@babel/preset-env', { modules: false }] ], plugins: [ plugin.plugin() ] };
Debug
Known issues
gotchaImport specifiers already mapped are replaced; last mapping in array wins.
fix
Ensure correct order when passing multiple maps.
affects: >=1.0.0
gotchaThe plugin does not validate import map JSON; malformed maps cause runtime errors.
fix
Validate import map JSON before loading.
affects: >=1.0.0
gotchaThe plugin only transforms static import/export statements, not dynamic import().
fix
Use a separate plugin or runtime polyfill for dynamic imports.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: plugin.load is not a function
Using default import instead of namespace import.
fix
import * as plugin from 'babel-plugin-import-map'
Error: Could not find import map file: source/import-map.json
File path is relative to current working directory, not Babel config location.
fix
Use absolute path or path relative to process.cwd()
TypeError: Cannot read properties of undefined (reading 'imports')
Passing an object without 'imports' key or empty object.
fix
Ensure import map object has 'imports' key.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
17 hits · last 30 days
node
16
OpenAI (training)
1
Resources
babel-plugin-import-map — npm install babel-plugin-import-map · libregistry