Registry / web-framework / babel-plugin-module-resolve

babel-plugin-module-resolve

JSON →
library1.7.0jsnpmunverified

A Babel plugin that allows module imports using Webpack-like aliases and custom root directories, resolving paths similar to webpack's enhanced-resolve. Version 1.7.0 (current stable) last released in 2022 with low release cadence. It supports both custom alias configuration and automatic usage of jsconfig/tsconfig paths, making it a lightweight alternative to babel-plugin-module-resolver. Includes TypeScript types and supports ESM and CJS import patterns.

npm install babel-plugin-module-resolve
INSTALL
IMPORT
SIG · BABEL-PLUGIN-MODUL
B
babel-plugin-module-resolve
web-frameworkjavascriptv1.7.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
module.exports = require('babel-plugin-module-resolve')
import plugin from 'babel-plugin-module-resolve'
For use in .babelrc or Babel config files; import is not used directly in code. Plugin is CommonJS by default.
plugin
plugins: [['module-resolve', { roots: ['./src'] }]]
plugins: ['babel-plugin-module-resolve']
Plugin name in config is 'module-resolve', not the full package name.

Basic setup with alias configuration to simplify import paths.

// Install: npm install --save-dev babel-plugin-module-resolve // In .babelrc or babel.config.js: { "plugins": [ ["module-resolve", { "roots": ["./src"], "alias": { "@utils": "./src/utils", "components": "./src/components" } }] ] } // Now import using alias: import { helper } from '@utils/helper'; // resolves to ./src/utils/helper
Debug
Known issues
gotchaPlugin uses enhanced-resolve internally; resolving behavior may differ from Babel's default path resolution for symlinks or non-standard file structures.
fix
Test paths thoroughly; if issues arise, use absolute paths in alias.
affects: >=1.0
breakingVersion 1.0 changed default alias from mapping '@' to 'src' to no default alias unless specified in config or tsconfig.
fix
If upgrading from <1.0, explicitly configure alias or use tsconfig paths.
affects: >=1.0
gotchaPlugin resolves based on the file's location, not the project root. Relative aliases may behave unexpectedly.
fix
Use absolute paths in alias or set roots to an absolute path.
affects: >=1.0
Errors
Common errors & fixes
Error: Cannot find module '@utils'
Alias not configured or roots not set correctly.
fix
Add alias in plugin options: { alias: { '@utils': './src/utils' } }
Module not found: Can't resolve 'components/Button' in '/path/to/file'
Alias is not resolving the path correctly.
fix
Check that the alias mapping is correct and the directory exists. Use absolute paths if needed.
Upgrade
Version history
1.7.0latest on npm
Audit
Dependencies
@babel/corerequiredPeer dependency required for Babel plugin functionality
Agent activity
16 hits · last 30 days
node
12
OpenAI (training)
1
Resources
babel-plugin-module-resolve — npm install babel-plugin-module-resolve · libregistry