Babel plugin that allows import and require with root-based paths, replacing relative path traversal (e.g., `../../../`) with a configurable prefix like `~/` or `@/`. Version 6.6.0 is the current stable release, actively maintained. Key differentiators: simple setup, multiple custom root path rules, support for dynamic imports and template literals. Still widely used but newer alternatives like `babel-plugin-module-resolver` offer more features (e.g., aliasing, TypeScript). Release cadence is irregular; last major update in 2020.
npm install babel-plugin-root-importVerified import paths — ran on the pinned version, not inferred.
Shows how to configure the plugin with custom prefix and suffix, and use it with static require/import and dynamic import with template literals.
Set rootPathSuffix to './src' (or your source directory) in plugin options.
Use '~/' or another prefix that does not start with '@'.
Upgrade to >=6.2.0 or ensure prefix is at least 2 characters long (excluding slash).
If using a bundler, configure corresponding aliases (e.g., in webpack resolve.alias) to match the root prefix.
Add equivalent path mappings in tsconfig.json compilerOptions.paths.
Ensure plugin is in .babelrc plugins array and rootPathSuffix is correct relative to CWD.
Run 'npm install --save-dev babel-plugin-root-import' or 'yarn add --dev babel-plugin-root-import'.
Use nested array format: ['babel-plugin-root-import', { rootPathPrefix: '~/' }].Upgrade to v6.6.0 or later, or avoid template literals (use simple string literals).
No dependency data recorded yet.