{"id":19102,"library":"babel-plugin-mock-imports","title":"babel-plugin-mock-imports","description":"Babel plugin for redirecting import statements to different locations. Current version 1.2.0, first released as 0.0.1. Key differentiator: simple configuration via RegExp patterns, useful for mocking modules or aliasing imports. Stable API with minimal changes.","status":"active","version":"1.2.0","language":"javascript","source_language":"en","source_url":"https://github.com/teod/babel-plugin-mock-imports","tags":["javascript"],"install":[{"cmd":"npm install babel-plugin-mock-imports","lang":"bash","label":"npm"},{"cmd":"yarn add babel-plugin-mock-imports","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-plugin-mock-imports","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The plugin is a Babel plugin and should be listed in Babel configuration, not directly required in code.","wrong":"require('babel-plugin-mock-imports')","symbol":"plugin","correct":"['mock-imports', { redirects: [...] }] in .babelrc or babel.config.js"},{"note":"Pattern is a string that will be passed to RegExp constructor, not a RegExp literal.","wrong":"pattern: /.svg$/","symbol":"redirects","correct":"pattern: '.(svg)$', location: 'path/to/mock'"},{"note":"Plugin does not ship TypeScript types. For Babel config typing, use @types/babel__core.","symbol":"type definition","correct":"No official type definitions; use @types/babel__core for general Babel types."}],"quickstart":{"code":"module.exports = {\n  plugins: [\n    ['mock-imports', {\n      redirects: [\n        {\n          pattern: '.svg$',\n          location: 'path/to/mocked/react/component'\n        }\n      ]\n    }]\n  ]\n};","lang":"javascript","description":"Redirects all .svg imports to a mock component."},"warnings":[{"fix":"Escape regex special characters in pattern strings, or use strings that are safe for RegExp.","message":"Pattern strings are evaluated as RegExp; special characters must be escaped correctly.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Ensure mock modules export the same symbols as the original modules.","message":"Plugin replaces import source strings but does not transform default/namespace imports; ensure mock modules export the same interface.","severity":"gotcha","affected_versions":">=0.0.1"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Use an array: ['mock-imports', { redirects: [...] }]","cause":"Plugins array item is incorrectly formatted.","error":"Error: .babelrc plugin is not a string or object/fn"},{"fix":"Ensure options object has 'redirects' array.","cause":"Plugin options object is missing or incorrect.","error":"TypeError: Cannot read property 'redirects' of undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}