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-rewriteVerified import paths — ran on the pinned version, not inferred.
Shows minimal Babel config and the transformation of a bare import to a URL path for browser use.
If you rely on symlink resolution, set preserveSymlinks: false in plugin options.
Remove the option from your config.
Always set modulesDir to an absolute URL path like '/node_modules' or use the default.
Ensure the most important node_modules directory is first in the array.
Upgrade Node.js to version 10.13.0 or later.
Use the plugin only in synchronous Babel transformations; wrap async calls if needed.
Run 'npm install @babel/core' to install the peer dependency.
Use 'import bareImportRewrite from 'babel-plugin-bare-import-rewrite'' (default) or 'import { default as bareImportRewrite } from '...'Use 'const { resolve } = require('babel-plugin-bare-import-rewrite');' instead.Install the missing module with 'npm install lodash' or check the module name.