Registry /
testing / babel-plugin-require-context-hook
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.
register
✓ require('babel-plugin-require-context-hook/register')();
✗ import { register } from 'babel-plugin-require-context-hook/register'
The register module exports a function that must be called immediately; it is not a default export.
plugin
✓ // in .babelrc: "plugins": ["require-context-hook"]
✗ require('babel-plugin-require-context-hook').default
The plugin is a Babel plugin, not a direct JavaScript import. Add it to your Babel configuration.
require.context
✓ const modules = require.context('./components', true, /\.js$/);
✗ import { context } from 'babel-plugin-require-context-hook'
require.context is a Webpack feature; this plugin makes it available in Node by rewriting calls.
Shows installation, Babel configuration, registering the global helper, and using require.context() in a Node script.
// Install: npm install --save-dev babel-plugin-require-context-hook
// .babelrc
{
"plugins": ["require-context-hook"]
}
// In your entry or test setup file (e.g., setup.js)
require('babel-plugin-require-context-hook/register')();
// Then use require.context() anywhere, e.g., in a Mocha test
const modules = require.context('./fixtures', true, /\.json$/);
modules.keys().forEach(key => {
const data = modules(key);
console.log(data);
});
Errors
Common errors & fixes
require.context is not a function
The register script was not called before trying to use require.context.
fixAdd require('babel-plugin-require-context-hook/register')() at the top of your entry file. TypeError: Cannot read property 'keys' of undefined
The Babel plugin is not configured or the register step is missing.
fixCheck .babelrc includes 'require-context-hook' in plugins, and the register function is called.
Module not found: Error: Cannot resolve module 'babel-plugin-require-context-hook'
The package is not installed in devDependencies.
fixRun npm install --save-dev babel-plugin-require-context-hook
Audit
Dependencies
No dependency data recorded yet.