{"id":20724,"library":"webpack-clear-require-cache-plugin","title":"Webpack Clear Require Cache Plugin","description":"A webpack plugin that clears modules from Node.js require.cache after the webpack compilation's afterEmit hook. Version 0.0.5, stable but limited maintenance. It accepts an array of regex patterns; during compilation, each cached module path is tested and removed if it matches. Primarily useful for development with npm-linked packages that need cache invalidation on rebuild. Works with webpack and Next.js servers. Simpler than using Nodemon or chokidar-based solutions, but limited to webpack-based projects.","status":"maintenance","version":"0.0.5","language":"javascript","source_language":"en","source_url":null,"tags":["javascript","webpack","plugin","clear","require","cache"],"install":[{"cmd":"npm install webpack-clear-require-cache-plugin","lang":"bash","label":"npm"},{"cmd":"yarn add webpack-clear-require-cache-plugin","lang":"bash","label":"yarn"},{"cmd":"pnpm add webpack-clear-require-cache-plugin","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Package uses CommonJS; no default ESM export. Use require for compatibility.","wrong":"import clearRequireCachePlugin from 'webpack-clear-require-cache-plugin';","symbol":"clearRequireCachePlugin","correct":"const clearRequireCachePlugin = require('webpack-clear-require-cache-plugin');"},{"note":"Plugin is a function that returns a webpack plugin object; do not use 'new' or pass an options object.","wrong":"new clearRequireCachePlugin({ patterns: [/my-module/] })","symbol":"plugin instance","correct":"clearRequireCachePlugin([/my-module/])"}],"quickstart":{"code":"const clearRequireCachePlugin = require('webpack-clear-require-cache-plugin');\n\nmodule.exports = {\n  // ... other webpack config\n  plugins: [\n    clearRequireCachePlugin([\n      /my-module/,\n    ]),\n  ],\n};","lang":"javascript","description":"Shows basic usage: import the plugin function and pass an array of regex patterns to clear require cache for linked modules."},"warnings":[{"fix":"Ensure you only use this plugin in server-side webpack configurations.","message":"Plugin only works in Node.js environments (e.g., webpack dev server, Next.js server-side builds). Does not affect client-side webpack bundles.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Consider using native webpack module federation or dedicated cache-clearing plugins for modern webpack.","message":"Package has not been updated since 2018; may not be compatible with webpack 5+ or Next.js built-in features.","severity":"deprecated","affected_versions":">=0.0.0"},{"fix":"Use patterns like /node_modules\\/my-module/ to avoid clearing unrelated modules.","message":"Regex patterns are tested against full module paths, not just module names. Include path separators or anchors if needed.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Disable filesystem cache when using this plugin: config.cache = false.","message":"Plugins that rely on require.cache may not work with webpack 5's persistent caching (filesystem cache).","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Use clearRequireCachePlugin([...]) without 'new'.","cause":"Using 'new' on the module export, which is a function, not a class.","error":"TypeError: clearRequireCachePlugin is not a constructor"},{"fix":"Run npm install --save-dev webpack-clear-require-cache-plugin and require with correct casing.","cause":"Missing npm install or incorrect import path.","error":"Cannot find module 'webpack-clear-require-cache-plugin'"},{"fix":"Change to const clearRequireCachePlugin = require('webpack-clear-require-cache-plugin');","cause":"Using ES import syntax for a CommonJS-only package.","error":"Module not found: Error: Can't resolve 'webpack-clear-require-cache-plugin'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}