{"id":19030,"library":"babel-plugin-bare-import-rewrite","title":"babel-plugin-bare-import-rewrite","description":"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.","status":"active","version":"2.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/cfware/babel-plugin-bare-import-rewrite","tags":["javascript","babel","esm","browser","import"],"install":[{"cmd":"npm install babel-plugin-bare-import-rewrite","lang":"bash","label":"npm"},{"cmd":"yarn add babel-plugin-bare-import-rewrite","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-plugin-bare-import-rewrite","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency: Babel plugin requires @babel/core to function.","package":"@babel/core","optional":false}],"imports":[{"note":"The package has a named export 'resolve' for programmatic use. In CJS, you can destructure from require.","wrong":"const resolve = require('babel-plugin-bare-import-rewrite').resolve","symbol":"resolve","correct":"import { resolve } from 'babel-plugin-bare-import-rewrite'"},{"note":"The plugin is the default export. For CJS, require returns the plugin function directly (no .default).","wrong":"const bareImportRewrite = require('babel-plugin-bare-import-rewrite')","symbol":"default","correct":"import bareImportRewrite from 'babel-plugin-bare-import-rewrite'"},{"note":"Common mistake: importing the whole module instead of destructuring resolve.","wrong":"const resolve = require('babel-plugin-bare-import-rewrite')","symbol":"resolve","correct":"const { resolve } = require('babel-plugin-bare-import-rewrite')"}],"quickstart":{"code":"// .babelrc\n{\n  \"plugins\": [\n    [\"bare-import-rewrite\", {\n      \"modulesDir\": \"/node_modules\",\n      \"alwaysRootImport\": [\"lodash\"],\n      \"failOnUnresolved\": true\n    }]\n  ]\n}\n\n// Input: import _ from 'lodash';\n// Output: import _ from '/node_modules/lodash/index.js';","lang":"javascript","description":"Shows minimal Babel config and the transformation of a bare import to a URL path for browser use."},"warnings":[{"fix":"If you rely on symlink resolution, set preserveSymlinks: false in plugin options.","message":"In version 2.0.0, the default value of 'preserveSymlinks' changed from false to true.","severity":"breaking","affected_versions":"2.0.0"},{"fix":"Remove the option from your config.","message":"The option 'processAtProgramExit' is deprecated and may be removed in a future major version.","severity":"deprecated","affected_versions":">=2.0.0"},{"fix":"Always set modulesDir to an absolute URL path like '/node_modules' or use the default.","message":"If 'modulesDir' is not set, the plugin may generate relative paths that break in different deployment contexts.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure the most important node_modules directory is first in the array.","message":"Resolving modules from multiple directories using 'resolveDirectories' requires careful ordering; leftmost takes precedence.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Upgrade Node.js to version 10.13.0 or later.","message":"Node.js 10 or above is required; older versions are unsupported.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Use the plugin only in synchronous Babel transformations; wrap async calls if needed.","message":"The 'resolve' export is synchronous and should not be used for async workflows.","severity":"gotcha","affected_versions":">=1.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/core' to install the peer dependency.","cause":"@babel/core is a peer dependency not installed.","error":"Error: Cannot find module '@babel/core'"},{"fix":"Use 'import bareImportRewrite from 'babel-plugin-bare-import-rewrite'' (default) or 'import { default as bareImportRewrite } from '...'","cause":"Importing the default export incorrectly in ESM.","error":"TypeError: plugin is not a function"},{"fix":"Use 'const { resolve } = require('babel-plugin-bare-import-rewrite');' instead.","cause":"Calling require('babel-plugin-bare-import-rewrite') and then treating it as the resolve function.","error":"The 'resolve' method throws 'Cannot read property 'split' of undefined'"},{"fix":"Install the missing module with 'npm install lodash' or check the module name.","cause":"Module not found in node_modules or 'failOnUnresolved' is set to false causing silent failure.","error":"Uncaught Error: Cannot find module 'lodash' while resolving bare import"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}