A Babel plugin that allows you to use root-based import paths (e.g., `~/foo`) instead of long relative paths (`../../../foo`). The current stable version is v5.4.0, with an active maintenance status (the latest release v6.6.0 came later but the package appears to be maintained). It supports custom prefix and suffix, multiple path mappings, and works with both `import` and `require`. Compared to Webpack's alias feature, this plugin operates at the Babel level, making it useful for tools like `babel-node` and testing environments where Webpack resolve is not available. It requires Babel 7 (or 6 depending on version).
npm install babel-7-plugin-root-importVerified import paths — ran on the pinned version, not inferred.
Installs the plugin, configures .babelrc with a root path suffix pointing to 'src', and demonstrates using the ~ prefix to import a module relative to the project root.
Update your .babelrc to use 'babel-plugin-root-import' instead of 'babel-root-import'.
Consider using Webpack's resolve.alias instead of this plugin if you are already using Webpack. If you must use both, ensure the plugin's rootPathPrefix does not clash with Webpack aliases.
Add 'import/resolver' configuration in your ESLint config: {"babel-plugin-root-import": {}}Explicitly set 'rootPathSuffix' to the directory relative to which you want root imports to resolve (e.g., 'src').
Check your .babelrc: ensure 'babel-plugin-root-import' is in the plugins array and that 'rootPathSuffix' points to the correct subdirectory containing your source files. Also verify that Babel is actually running on the file (e.g., through webpack loader or babel-node).
Change 'rootPrefix' to 'rootPathPrefix' in your .babelrc options.
Install an older version of the plugin: npm install babel-plugin-root-import@5 --save-dev (v5.x supports Babel 6) or upgrade your project to Babel 7.