A Babel plugin that allows custom module resolution by defining root directories and aliases, eliminating deep relative imports like '../../../../utils'. It simplifies import/require paths for cleaner code. Current stable version is 5.0.3 (July 2024). Release cadence is irregular, with major version bumps occasionally (v4 in 2020, v5 in 2023). Key differentiators: supports both import and require, works with Babel 7+, and integrates with ESLint via eslint-import-resolver-babel-module for linting. Alternative: TypeScript's paths in tsconfig.json but this plugin works for plain JavaScript/Babel projects.
npm install babel-plugin-module-resolverVerified import paths — ran on the pinned version, not inferred.
Configures the plugin in .babelrc with root and alias, then shows a simplified import path.
Prefix alias paths with ./ or ../ to enforce relative resolution, or update alias values to match the new semantics.
Add eslint-import-resolver-babel-module to your ESLint config and set the same root/alias options.
Configure Webpack resolve.alias or TypeScript paths separately for runtime.
Replace 'cwd' with 'root' and use absolute paths or './src' relative to project root.
Ensure the alias value is correct and the directory exists. Use absolute paths or './src' relative to project root.
Run `npm install --save-dev babel-plugin-module-resolver` or `yarn add --dev babel-plugin-module-resolver`.
Replace 'cwd' with 'root' and use absolute paths or './src' relative to project root.