Registry / serialization / babel-project-relative-import

babel-project-relative-import

JSON →
library2.0.1jsnpmunverified

Babel plugin (v2.0.1) that transforms project-relative import paths (e.g., '~') into file-relative paths during build. Unlike alternatives like babel-root-import that convert to absolute paths, this plugin produces relative output for portability across systems. Tested with babel-cli, webpack, and task runners. Last release appears stable, but the project is in maintenance mode with infrequent updates.

npm install babel-project-relative-import
INSTALL
IMPORT
SIG · BABEL-PROJECT-RELA
B
babel-project-relative-import
serializationjavascriptv2.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 = require('babel-project-relative-import');
import plugin from 'babel-project-relative-import';
This is a Babel plugin, not a regular module. It is used via Babel config, not imported directly in source code.
plugin config
plugins: [['babel-project-relative-import', { sourceDir: 'src/', importPathPrefix: '~' }]]
plugins: ['babel-project-relative-import']
Options are optional. Without options, uses default prefix '~' and no sourceDir.
import with prefix
import Test from '~/otherdir/example.js';
import Test from '~otherdir/example.js';
The default prefix includes a slash. If you set a custom prefix like '^', you need to include the slash manually in the import.

Shows installation, Babel config, and transformation of a project-relative import.

// Install npm install babel-project-relative-import // .babelrc { "plugins": [ "babel-project-relative-import" ] } // Source file: src/app/index.js import Helper from '~/lib/helper.js'; console.log(Helper); // After Babel transform, output becomes: // import Helper from './../lib/helper.js';
Debug
Known issues
breakingOption `projectPathSuffix` renamed to `sourceDir` in v2
fix
Rename option to `sourceDir` in Babel config.
affects: >=2.0.0
breakingOption `importPathPrefix` no longer auto-adds trailing slash in v2
fix
If you need a slash, include it in the prefix value (e.g., '^/').
affects: >=2.0.0
gotchaWebpack users may not need this plugin; use resolve.alias instead
fix
Consider using Webpack's resolve.alias for similar behavior without Babel transform.
affects: all
gotchaPlugin only transforms imports with prefix; other imports left untouched
fix
Ensure your project-relative imports use the configured prefix (default: '~/').
affects: all
deprecatedNot actively maintained; last release in 2019
fix
Consider migrating to modern alternatives like babel-plugin-module-resolver.
affects: all
Errors
Common errors & fixes
Cannot find module 'babel-project-relative-import'
Plugin not installed or typo in package name
fix
Run `npm install babel-project-relative-import --save-dev` and check .babelrc for correct spelling.
Error: Option "projectPathSuffix" is not supported
Using v2 config option from v1
fix
Rename option to "sourceDir" in plugin configuration.
The import path '~/dir/file.js' was not transformed correctly
Missing or incorrect sourceDir configuration
fix
Set sourceDir to project subdirectory (e.g., "src/") so the plugin can compute correct relative path.
Import with prefix '^' is not being transformed
Custom prefix without trailing slash, but import path also lacks slash
fix
If prefix is '^', use '^/dir/file' or change prefix to '^/'.
Windows: paths contain backslashes
Plugin uses forward slashes; Babel might produce backslashes
fix
Ensure Babel config normalizes paths or use a post-transform step.
Upgrade
Version history
2.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
14 hits · last 30 days
node
12
OpenAI (training)
1
Resources
babel-project-relative-import — npm install babel-project-relative-import · libregistry