{"id":19076,"library":"babel-plugin-import-redirect","title":"babel-plugin-import-redirect","description":"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.","status":"maintenance","version":"1.1.1","language":"javascript","source_language":"en","source_url":"https://github.com/Velenir/babel-plugin-import-redirect","tags":["javascript","babel","babel-plugin","import","redirect","require","export","path","rewrite"],"install":[{"cmd":"npm install babel-plugin-import-redirect","lang":"bash","label":"npm"},{"cmd":"yarn add babel-plugin-import-redirect","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-plugin-import-redirect","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"CommonJS-only; no default ESM export.","symbol":"default","correct":"module.exports = require('babel-plugin-import-redirect')"}],"quickstart":{"code":"// .babelrc\n{\n  \"plugins\": [\n    [\"import-redirect\", {\n      \"root\": \"./tests/mocks\",\n      \"redirect\": {\n        \"connect\": \"./connect.mocked\",\n        \"\\\\.css$\": false\n      }\n    }]\n  ]\n}\n\n// src/index.js\nimport connect from 'connect';\nimport './style.css';\n// Transpiles to:\n// import connect from '../tests/mocks/connect.mocked';\n// (style.css import removed because redirected to false)","lang":"javascript","description":"Shows basic plugin setup with root and redirect map, and how source code changes."},"warnings":[{"fix":"Add 'syntax-dynamic-import' to plugins array before 'import-redirect'.","message":"Dynamic import() requires babel-plugin-syntax-dynamic-import to be listed before import-redirect.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use double backslashes (e.g., '\\\\.css$' for .css files).","message":"Regex redirect keys must be supplied as strings; escaping backslashes is required in JSON.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure no code expects the removed import, or use a mock file instead.","message":"Redirect value false removes the import entirely, but this may cause missing variable errors.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run npm install --save-dev babel-plugin-import-redirect","cause":"Plugin not installed or missing from node_modules.","error":"Error: Cannot find module 'babel-plugin-import-redirect'"},{"fix":"Include @babel/plugin-transform-runtime or use @babel/polyfill","cause":"Using async/await or generators without proper polyfill; not directly related to this plugin.","error":"ReferenceError: regeneratorRuntime is not defined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}