Babel plugin to enable root-relative imports (e.g., import Foo from '@/foo') in JavaScript/TypeScript projects. Version 4.1.8 is the legacy package, renamed to babel-plugin-root-import (latest v6.6.0). This plugin transforms root-relative paths to relative paths at build time. Key differentiator: simple configuration (rootPathSuffix) and support for dynamic imports. Often confused with webpack aliases but works at Babel level. Low release cadence: last update 2019. Consider using babel-plugin-root-import instead, which is the maintained successor.
npm install babel-root-importVerified import paths — ran on the pinned version, not inferred.
Shows installation, .babelrc configuration with custom root suffix and prefix, and an example import resolving to a src-relative path.
Use babel-plugin-root-import instead. Requires uninstalling this package and installing the new one.
Update prefix in code and configuration to '@/' or set a custom prefix.
Use array syntax: ["babel-root-import", { rootPathSuffix: "src" }]Set rootPathSuffix to your source directory (e.g., 'src') or adjust it appropriately.
Ensure babel-root-import is installed and configured with rootPathSuffix and rootPathPrefix in .babelrc or babel.config.js.
Add a corresponding alias in webpack config (resolve.alias) or use a different root import approach.
Ensure your code is transpiled with Babel before running, or use node with a require hook like @babel/register.