Registry / testing / babel-plugin-import-redirect

babel-plugin-import-redirect

JSON →
library1.1.1jsnpmunverified

A Babel plugin (v1.1.1) that rewrites import, export from, require() and dynamic import() paths to custom destinations, primarily used for mocking in tests. Last updated in 2017, it supports regex-based redirects, extra function handling, and global replacements. Unlike module aliases or webpack resolve aliases, this operates at the Babel AST level, allowing fine-grained control per file. Requires Node >=4 and babel 6/7.

npm install babel-plugin-import-redirect
INSTALL
IMPORT
SIG · BABEL-PLUGIN-IMPOR
B
babel-plugin-import-redirect
testingjavascriptv1.1.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-plugin-import-redirect')
CommonJS-only; no default ESM export.

Shows basic plugin setup with root and redirect map, and how source code changes.

// .babelrc { "plugins": [ ["import-redirect", { "root": "./tests/mocks", "redirect": { "connect": "./connect.mocked", "\\.css$": false } }] ] } // src/index.js import connect from 'connect'; import './style.css'; // Transpiles to: // import connect from '../tests/mocks/connect.mocked'; // (style.css import removed because redirected to false)
Debug
Known issues
gotchaDynamic import() requires babel-plugin-syntax-dynamic-import to be listed before import-redirect.
fix
Add 'syntax-dynamic-import' to plugins array before 'import-redirect'.
affects: >=1.0.0
gotchaRegex redirect keys must be supplied as strings; escaping backslashes is required in JSON.
fix
Use double backslashes (e.g., '\\.css$' for .css files).
affects: >=1.0.0
gotchaRedirect value false removes the import entirely, but this may cause missing variable errors.
fix
Ensure no code expects the removed import, or use a mock file instead.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'babel-plugin-import-redirect'
Plugin not installed or missing from node_modules.
fix
Run npm install --save-dev babel-plugin-import-redirect
ReferenceError: regeneratorRuntime is not defined
Using async/await or generators without proper polyfill; not directly related to this plugin.
fix
Include @babel/plugin-transform-runtime or use @babel/polyfill
Upgrade
Version history
1.1.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
18 hits · last 30 days
node
16
OpenAI (training)
1
Resources
babel-plugin-import-redirect — npm install babel-plugin-import-redirect · libregistry