Registry /
testing / babel-plugin-mock-imports
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
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
plugin
✓ ['mock-imports', { redirects: [...] }] in .babelrc or babel.config.js
✗ require('babel-plugin-mock-imports')
The plugin is a Babel plugin and should be listed in Babel configuration, not directly required in code.
redirects
✓ pattern: '.(svg)$', location: 'path/to/mock'
✗ pattern: /.svg$/
Pattern is a string that will be passed to RegExp constructor, not a RegExp literal.
type definition
✓ No official type definitions; use @types/babel__core for general Babel types.
Plugin does not ship TypeScript types. For Babel config typing, use @types/babel__core.
Redirects all .svg imports to a mock component.
module.exports = {
plugins: [
['mock-imports', {
redirects: [
{
pattern: '.svg$',
location: 'path/to/mocked/react/component'
}
]
}]
]
};
Errors
Common errors & fixes
Error: .babelrc plugin is not a string or object/fn
Plugins array item is incorrectly formatted.
fixUse an array: ['mock-imports', { redirects: [...] }] TypeError: Cannot read property 'redirects' of undefined
Plugin options object is missing or incorrect.
fixEnsure options object has 'redirects' array.
Audit
Dependencies
No dependency data recorded yet.