babel-root-slash-import

raw JSON →
1.1.0 verified Sat Apr 25 auth: no javascript maintenance

A Babel plugin that allows import statements to use root-based paths starting with '/' instead of relative paths like '../../../'. Version 1.1.0 is the latest stable release. It has no updates in recent years and is likely in maintenance mode. Compared to alternatives like babel-plugin-module-resolver, this plugin has a simpler API but offers less configuration and flexibility.

error Error: Cannot find module 'babel-core'
cause Missing Babel peer dependency or incompatibility with Babel 7+.
fix
Ensure babel-core is installed (npm install --save-dev @babel/core) or use a more modern plugin.
deprecated Plugin has not been updated since 2017 and may not work with modern Babel versions.
fix Consider using babel-plugin-module-resolver instead.
npm install babel-root-slash-import
yarn add babel-root-slash-import
pnpm add babel-root-slash-import

Shows basic usage with default root and custom rootPathSuffix option.

// .babelrc
{
  "plugins": ["babel-root-slash-import"]
}

// Then in your source file:
import MyModule from '/my-module.js';
console.log(MyModule);

// To use a custom root, e.g., src/js:
// .babelrc
{
  "plugins": [
    ["babel-root-slash-import", {
      "rootPathSuffix": "src/js"
    }]
  ]
}
// Then import from 'src/js' root:
import Button from '/app/Button.js'; // resolves to src/js/app/Button.js