Registry / devops / module-replace-webpack-plugin

module-replace-webpack-plugin

JSON →
library0.0.12jsnpmunverified

A webpack plugin (v0.0.12, latest as of 2025) that replaces imported modules at build time, allowing monkey patching of third-party libraries without modifying source code. Designed for webpack 3.x only. Uses regex-based matching to swap `require`/`import` statements. No updates since 2018; limited compatibility and no support for webpack 4+ or ESM. Different from string-replace-loader as it operates on module resolution rather than string substitution.

npm install module-replace-webpack-plugin
INSTALL
IMPORT
SIG · MODULE-REPLACE-WEB
M
module-replace-webpack-plugin
devopsjavascriptv0.0.12
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.

ModuleReplaceWebpackPlugin
const ModuleReplaceWebpackPlugin = require('module-replace-webpack-plugin');
import ModuleReplaceWebpackPlugin from 'module-replace-webpack-plugin';
Plugin does not provide ES module exports; use CommonJS require() only.
new ModuleReplaceWebpackPlugin(options)
new ModuleReplaceWebpackPlugin({ modules: [{ test: /lodash/, replace: './patched.js' }] })
new ModuleReplaceWebpackPlugin({ modules: { test: /lodash/, replace: './patched.js' } })
options.modules must be an array of objects, not a single object.
exclude
new ModuleReplaceWebpackPlugin({ modules: [...], exclude: [/patched\.js$/] })
new ModuleReplaceWebpackPlugin({ modules: [...], exclude: ['patched.js'] })
exclude must be an array of RegExp, not strings.

Configures webpack to replace all imports matching /lodash/ with a local patched file, excluding the patched file itself from replacement.

const ModuleReplaceWebpackPlugin = require('module-replace-webpack-plugin'); const path = require('path'); module.exports = { entry: './src/index.js', output: { filename: 'bundle.js', path: path.resolve(__dirname, 'dist') }, plugins: [ new ModuleReplaceWebpackPlugin({ modules: [{ test: /lodash/, replace: './src/patchedLodash.js' }], exclude: [/patchedLodash\.js$/] }) ] };
Debug
Known issues
deprecatedPlugin only supports webpack 3.x; may break on webpack 4+.
fix
Upgrade to a modern alternative like string-replace-loader or NormalModuleReplacementPlugin.
affects: >=4.0.0
gotchaThe 'replace' path must be relative to root; does not automatically resolve from entry directory.
fix
Use path.resolve(__dirname, 'src/patched.js') to specify absolute path.
affects: >=0.0.1
gotchaMultiple module rules are matched first-come-first-serve; overlapping regexes may cause unexpected replacement.
fix
Order specific regexes before generic ones in the modules array.
affects: >=0.0.1
gotchaFile extension in 'replace' is mandatory; omitting it will not work.
fix
Always include file extension, e.g., './patched.js' not './patched'.
affects: >=0.0.1
Errors
Common errors & fixes
Error: ModuleReplaceWebpackPlugin is not a constructor
Using ES module import instead of CommonJS require.
fix
Use const ModuleReplaceWebpackPlugin = require('module-replace-webpack-plugin');
TypeError: Cannot read property 'push' of undefined
options.modules is not an array or is missing.
fix
Ensure options contains modules: [{ test: /.../, replace: '...' }]
Upgrade
Version history
0.0.12latest on npm
Audit
Dependencies
webpackrequiredPeer dependency: plugin uses webpack plugin API (tested on webpack 3.x only; may not work with newer versions).
Agent activity
6 hits · last 30 days
node
6
Resources
module-replace-webpack-plugin — npm install module-replace-webpack-plugin · libregistry