Registry / devops / babel-plugin-bare-import-rewrite

babel-plugin-bare-import-rewrite

JSON →
library2.0.0jsnpmunverified

A Babel plugin that rewrites bare import specifiers (like 'lodash') to browser-compatible URL-based paths for use without a bundler, currently at stable version 2.0.0. It resolves bare imports to absolute or relative URLs pointing to node_modules on a web server, with configurable options like modulesDir, alwaysRootImport, and ignorePrefixes. This plugin is a pragmatic solution until native import maps gain full browser support, making it distinct from bundler-based approaches like Webpack or Rollup. It supports ESM, CJS, and TypeScript projects using Babel, actively maintained, and requires @babel/core >=7.8.3.

npm install babel-plugin-bare-import-rewrite
INSTALL
IMPORT
SIG · BABEL-PLUGIN-BARE-
B
babel-plugin-bare-import-rewrite
devopsjavascriptv2.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.

resolve
import { resolve } from 'babel-plugin-bare-import-rewrite'
const resolve = require('babel-plugin-bare-import-rewrite').resolve
The package has a named export 'resolve' for programmatic use. In CJS, you can destructure from require.
default
import bareImportRewrite from 'babel-plugin-bare-import-rewrite'
const bareImportRewrite = require('babel-plugin-bare-import-rewrite')
The plugin is the default export. For CJS, require returns the plugin function directly (no .default).
resolve
const { resolve } = require('babel-plugin-bare-import-rewrite')
const resolve = require('babel-plugin-bare-import-rewrite')
Common mistake: importing the whole module instead of destructuring resolve.

Shows minimal Babel config and the transformation of a bare import to a URL path for browser use.

// .babelrc { "plugins": [ ["bare-import-rewrite", { "modulesDir": "/node_modules", "alwaysRootImport": ["lodash"], "failOnUnresolved": true }] ] } // Input: import _ from 'lodash'; // Output: import _ from '/node_modules/lodash/index.js';
Debug
Known issues
breakingIn version 2.0.0, the default value of 'preserveSymlinks' changed from false to true.
fix
If you rely on symlink resolution, set preserveSymlinks: false in plugin options.
affects: 2.0.0
deprecatedThe option 'processAtProgramExit' is deprecated and may be removed in a future major version.
fix
Remove the option from your config.
affects: >=2.0.0
gotchaIf 'modulesDir' is not set, the plugin may generate relative paths that break in different deployment contexts.
fix
Always set modulesDir to an absolute URL path like '/node_modules' or use the default.
affects: >=1.0.0
gotchaResolving modules from multiple directories using 'resolveDirectories' requires careful ordering; leftmost takes precedence.
fix
Ensure the most important node_modules directory is first in the array.
affects: >=1.0.0
breakingNode.js 10 or above is required; older versions are unsupported.
fix
Upgrade Node.js to version 10.13.0 or later.
affects: >=2.0.0
gotchaThe 'resolve' export is synchronous and should not be used for async workflows.
fix
Use the plugin only in synchronous Babel transformations; wrap async calls if needed.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module '@babel/core'
@babel/core is a peer dependency not installed.
fix
Run 'npm install @babel/core' to install the peer dependency.
TypeError: plugin is not a function
Importing the default export incorrectly in ESM.
fix
Use 'import bareImportRewrite from 'babel-plugin-bare-import-rewrite'' (default) or 'import { default as bareImportRewrite } from '...'
The 'resolve' method throws 'Cannot read property 'split' of undefined'
Calling require('babel-plugin-bare-import-rewrite') and then treating it as the resolve function.
fix
Use 'const { resolve } = require('babel-plugin-bare-import-rewrite');' instead.
Uncaught Error: Cannot find module 'lodash' while resolving bare import
Module not found in node_modules or 'failOnUnresolved' is set to false causing silent failure.
fix
Install the missing module with 'npm install lodash' or check the module name.
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies
@babel/corerequiredPeer dependency: Babel plugin requires @babel/core to function.
Agent activity
12 hits · last 30 days
node
10
Amazon
1
OpenAI (training)
1
Resources
babel-plugin-bare-import-rewrite — npm install babel-plugin-bare-import-rewrite · libregistry