eslint-import-resolver-root-import
raw JSON → 1.0.4 verified Sat Apr 25 auth: no javascript
ESLint resolver for babel-plugin-root-import that enables custom root-based module import aliases (e.g., '~/components/MyComponent'). Version 1.0.4 is stable and maintained. It works with babel-plugin-root-import >=5.1.0 and eslint-plugin-import >=1.9.2. Key differentiator: it uses babel.config.js for automatic configuration of rootPathSuffix and rootPathPrefix, unlike the original fork which required separate .babelrc settings. This package is tailored for React Native and other Babel projects that rely on root imports for cleaner import paths.
Common errors
error Error: No configuration found for root-import resolver. Please ensure babel-plugin-root-import is installed and configured. ↓
cause babel-plugin-root-import is not installed or babel.config.js is missing required config.
fix
Install babel-plugin-root-import and add rootPathPrefix/suffix to babel.config.js.
error Unable to resolve path to module '~/components/MyComponent' ↓
cause The root-import resolver is not properly configured or the path does not exist.
fix
Check that rootPathSuffix points to the correct directory relative to project root. Verify file extensions are included in the resolver settings.
Warnings
gotcha The resolver requires babel-plugin-root-import configuration to be present; otherwise root imports will not be resolved. ↓
fix Ensure babel-plugin-root-import is installed and configured in babel.config.js.
gotcha Settings in .eslintrc override the configuration from babel.config.js. If both are provided, .eslintrc takes precedence. ↓
fix Either remove conflicting settings from .eslintrc or ensure they match babel.config.js.
deprecated This package is a fork of an older resolver that used .babelrc. Newer versions of Babel use babel.config.js. ↓
fix Use babel.config.js (project-wide) instead of .babelrc.
gotcha The resolver only supports rootPathPrefix and rootPathSuffix; other babel-plugin-root-import options like rootPathStrategy are ignored. ↓
fix Avoid using unsupported options in resolver settings.
Install
npm install eslint-import-resolver-root-import yarn add eslint-import-resolver-root-import pnpm add eslint-import-resolver-root-import Imports
- default
import resolver from 'eslint-import-resolver-root-import'
Quickstart
// .eslintrc.js
module.exports = {
settings: {
'import/resolver': {
'root-import': {
rootPathPrefix: '~',
rootPathSuffix: 'src',
extensions: ['.js', '.jsx', '.ts', '.tsx']
}
}
},
rules: {
'import/no-unresolved': 'error'
}
};
// babel.config.js
module.exports = {
plugins: [
['babel-plugin-root-import', {
rootPathPrefix: '~',
rootPathSuffix: 'src'
}]
]
};