eslint-import-resolver-babel-plugin-root-import
raw JSON → 1.1.1 verified Sat Apr 25 auth: no javascript maintenance
A resolver for eslint-plugin-import that maps root-relative module paths (e.g., '@/', '~/') according to babel-plugin-root-import configuration. It reads settings from `.babelrc` or allows inline options in `.eslintrc`. This fork (v1.1.1) fixes compatibility with babel-plugin-root-import ^5.1.0, unlike the original resolver which only supported older versions. It is a small, single-purpose package with no updates since 2017, indicating stable functionality but potential deprecation risk due to newer alternatives like eslint-import-resolver-typescript.
Common errors
error Module not found: Error: Can't resolve '@/components/MyComponent' ↓
cause Resolver not configured or configuration mismatch between .babelrc and resolver settings.
fix
Ensure .eslintrc settings include 'import/resolver': 'babel-plugin-root-import' and babel-plugin-root-import is installed and configured.
error ESLint: Unable to resolve path to module '@/utils/helpers' (import/no-unresolved) ↓
cause Resolver not activated or missing peer dependency.
fix
Install eslint-plugin-import and eslint-import-resolver-babel-plugin-root-import, then add settings in .eslintrc.
error Cannot find module 'babel-plugin-root-import' ↓
cause Missing peer dependency babel-plugin-root-import.
fix
Run npm install --save-dev babel-plugin-root-import.
Warnings
gotcha Resolver only reads configuration from .babelrc file; it does not support babel.config.js or other modern Babel config formats. ↓
fix If using babel.config.js, pass options inline in .eslintrc as shown in the quickstart.
breaking Incompatible with eslint-plugin-import <1.9.2 due to resolver interface changes. ↓
fix Upgrade eslint-plugin-import to >=1.9.2.
deprecated Package is not actively maintained; last release in 2017. Consider alternatives like eslint-import-resolver-typescript or eslint-import-resolver-webpack. ↓
fix Migrate to a maintained resolver if encountering issues.
gotcha When using 'import/resolver' as an object, the resolver name must exactly match 'babel-plugin-root-import' (including hyphens). ↓
fix Use the exact string 'babel-plugin-root-import' as the key.
Install
npm install eslint-import-resolver-babel-plugin-root-import yarn add eslint-import-resolver-babel-plugin-root-import pnpm add eslint-import-resolver-babel-plugin-root-import Imports
- resolver wrong
using import/resolver: 'eslint-import-resolver-babel-plugin-root-import'correctsettings: { 'import/resolver': 'babel-plugin-root-import' }
Quickstart
// .eslintrc.json
{
"settings": {
"import/resolver": {
"babel-plugin-root-import": {
"rootPathPrefix": "@",
"rootPathSuffix": "src"
}
}
}
}
// With .babelrc configuration, just use:
// "import/resolver": "babel-plugin-root-import"
// .babelrc example:
{
"plugins": [
["babel-plugin-root-import", {
"rootPathPrefix": "~",
"rootPathSuffix": "src/js"
}]
]
}
// Then in code:
import MyComponent from '@/components/MyComponent'; // resolves to src/components/MyComponent
import utils from '~/utils/helpers'; // resolves to src/js/utils/helpers