Registry / webpack-requiredir

webpack-requiredir

JSON →
library0.2.1jsnpmunverified

This library provides a simple function to recursively require all modules from a webpack require.context, returning a hash of modules keyed by their names. Version 0.2.1 is the latest. It supports optional object modification, exclusion of specific modules, and applying a transformation function to each module. It is a minimal utility for use with webpack's require.context, primarily in Node.js or webpack-bundled applications. No active development; last updated in 2016.

npm install webpack-requiredir
INSTALL
IMPORT
SIG · WEBPACK-REQUIREDIR
W
webpack-requiredir
javascriptv0.2.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
const requireDir = require('webpack-requiredir');
import requireDir from 'webpack-requiredir';
Package does not provide ESM exports; CommonJS only.
requireDir
const requireDir = require('webpack-requiredir'); requireDir(require.context('./src', true, /\.js$/));
import { requireDir } from 'webpack-requiredir';
The package exports a single function as default.
require.context
const result = requireDir(require.context('./dir', true, /\.js$/));
const result = requireDir(require.context('./dir', true, /\.js$/), {});
Second argument is optional; if provided it must be an options object.

Shows how to require all .js files from ./src/components recursively, excluding index.js, and extracting default exports.

const requireDir = require('webpack-requiredir'); const context = require.context('./src/components', true, /\.js$/); const modules = requireDir(context, { exclude: ['index.js'], functionToApply: (module) => module.default || module }); console.log(modules);
Debug
Known issues
deprecatedPackage is no longer maintained; last update in 2016. Use dynamic imports or modern webpack context features instead.
fix
Replace with manual import() calls or webpack's require.context directly with custom logic.
affects: >=0.0.0
gotcharequire.context is webpack-specific; this library only works in a webpack-bundled environment.
fix
Ensure code is bundled with webpack; use only where require.context is available.
affects: >=0.0.0
gotchaThe resolved module keys are file paths relative to the context directory; not suitable for dynamic access without normalization.
fix
Map keys as needed (e.g., strip extensions and leading './').
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'webpack-requiredir'
Package may not be installed or the name is misspelled.
fix
Run: npm install webpack-requiredir
TypeError: require.context is not a function
Code is not running in a webpack-bundled environment (e.g., Node.js outside webpack).
fix
Ensure the code is part of a webpack bundle, or use a polyfill for require.context.
Unexpected token export
The package uses CommonJS, but your bundler expects ESM imports.
fix
Use require() instead of import, or configure your bundler to handle CommonJS.
Upgrade
Version history
0.2.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
webpack-requiredir — npm install webpack-requiredir · libregistry