Registry / devops / babel-plugin-relative-path-import

babel-plugin-relative-path-import

JSON →
library2.0.1jsnpmunverified

babel-plugin-relative-path-import (stable v2.0.1, Babel 7+) enables root-based import paths (e.g., '@actions/UserAction') as an alternative to deeply nested relative paths. Supports multiple custom prefix/suffix mappings. Differentiates from Webpack resolve aliases by working at the Babel transform level, allowing compatibility with tools that don't resolve Webpack aliases. Primarily used with Node.js/React projects. Last updated 2019, see more recent alternatives like babel-plugin-root-import.

npm install babel-plugin-relative-path-import
INSTALL
IMPORT
SIG · BABEL-PLUGIN-RELAT
B
babel-plugin-relative-path-import
devopsjavascriptv2.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
module.exports = { plugins: [['babel-plugin-relative-path-import', { paths: [{ rootPathPrefix: '@', rootPathSuffix: 'src' }] }]] }
import plugin from 'babel-plugin-relative-path-import';
Used as a Babel plugin in .babelrc or babel.config.js, not imported directly in source code.

Configures Babel to resolve '@'-prefixed imports relative to a 'src' directory.

// .babelrc { "plugins": [ [ "babel-plugin-relative-path-import", { "paths": [ { "rootPathPrefix": "@", "rootPathSuffix": "src" } ] } ] ] } // src/app.js import UserAction from '@actions/UserAction'; // resolves to src/actions/UserAction.js
Debug
Known issues
breakingVersion 2.0.0+ is only compatible with Babel 7; Babel 6 users must use v1.x.
fix
If on Babel 6, install version 1.0.5 or lower.
affects: >=2.0.0
deprecatedThe default rootPathPrefix changed from '@' in v1 to still '@' but the paths option now expects an array of objects instead of a single object.
fix
Update config to use array format as shown in README.
affects: >=2.0.0
gotchaThis plugin does not affect runtime resolution; paths are only transformed at build time. If using Node.js runtime without Babel, imports will fail.
fix
Ensure you use Babel for both build and runtime, or use a runtime resolver like module-alias.
affects: >=1.0.0
breakingThe plugin no longer supports the old single-object configuration schema from v1.
fix
Migrate to the new array-based paths configuration.
affects: >=2.0.0
Errors
Common errors & fixes
Error: Plugin/preset files are not allowed to export objects, only functions.
Attempting to import or use the plugin incorrectly in a JavaScript file that is not a Babel config.
fix
Use the plugin only as a string in Babel configuration, not as an imported module.
Module not found: Can't resolve '@/components/Button'
Path prefix not mapped correctly or plugin not applied during Webpack build.
fix
Verify rootPathSuffix is correct and that Babel plugin runs before Webpack resolves modules.
Upgrade
Version history
2.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
4
Amazon
1
Resources
babel-plugin-relative-path-import — npm install babel-plugin-relative-path-import · libregistry