{"id":20223,"library":"module-replace-webpack-plugin","title":"module-replace-webpack-plugin","description":"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.","status":"abandoned","version":"0.0.12","language":"javascript","source_language":"en","source_url":"https://github.com/nerdchacha/module-replace-webpack-plugin","tags":["javascript","webpack","plugin","replace","module-replace-webpack-plugin"],"install":[{"cmd":"npm install module-replace-webpack-plugin","lang":"bash","label":"npm"},{"cmd":"yarn add module-replace-webpack-plugin","lang":"bash","label":"yarn"},{"cmd":"pnpm add module-replace-webpack-plugin","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency: plugin uses webpack plugin API (tested on webpack 3.x only; may not work with newer versions).","package":"webpack","optional":false}],"imports":[{"note":"Plugin does not provide ES module exports; use CommonJS require() only.","wrong":"import ModuleReplaceWebpackPlugin from 'module-replace-webpack-plugin';","symbol":"ModuleReplaceWebpackPlugin","correct":"const ModuleReplaceWebpackPlugin = require('module-replace-webpack-plugin');"},{"note":"options.modules must be an array of objects, not a single object.","wrong":"new ModuleReplaceWebpackPlugin({ modules: { test: /lodash/, replace: './patched.js' } })","symbol":"new ModuleReplaceWebpackPlugin(options)","correct":"new ModuleReplaceWebpackPlugin({ modules: [{ test: /lodash/, replace: './patched.js' }] })"},{"note":"exclude must be an array of RegExp, not strings.","wrong":"new ModuleReplaceWebpackPlugin({ modules: [...], exclude: ['patched.js'] })","symbol":"exclude","correct":"new ModuleReplaceWebpackPlugin({ modules: [...], exclude: [/patched\\.js$/] })"}],"quickstart":{"code":"const ModuleReplaceWebpackPlugin = require('module-replace-webpack-plugin');\nconst path = require('path');\n\nmodule.exports = {\n  entry: './src/index.js',\n  output: {\n    filename: 'bundle.js',\n    path: path.resolve(__dirname, 'dist')\n  },\n  plugins: [\n    new ModuleReplaceWebpackPlugin({\n      modules: [{\n        test: /lodash/,\n        replace: './src/patchedLodash.js'\n      }],\n      exclude: [/patchedLodash\\.js$/]\n    })\n  ]\n};","lang":"javascript","description":"Configures webpack to replace all imports matching /lodash/ with a local patched file, excluding the patched file itself from replacement."},"warnings":[{"fix":"Upgrade to a modern alternative like string-replace-loader or NormalModuleReplacementPlugin.","message":"Plugin only supports webpack 3.x; may break on webpack 4+.","severity":"deprecated","affected_versions":">=4.0.0"},{"fix":"Use path.resolve(__dirname, 'src/patched.js') to specify absolute path.","message":"The 'replace' path must be relative to root; does not automatically resolve from entry directory.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Order specific regexes before generic ones in the modules array.","message":"Multiple module rules are matched first-come-first-serve; overlapping regexes may cause unexpected replacement.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Always include file extension, e.g., './patched.js' not './patched'.","message":"File extension in 'replace' is mandatory; omitting it will not work.","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 const ModuleReplaceWebpackPlugin = require('module-replace-webpack-plugin');","cause":"Using ES module import instead of CommonJS require.","error":"Error: ModuleReplaceWebpackPlugin is not a constructor"},{"fix":"Ensure options contains modules: [{ test: /.../, replace: '...' }]","cause":"options.modules is not an array or is missing.","error":"TypeError: Cannot read property 'push' of undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}