{"id":20507,"library":"remove-files-webpack-plugin","title":"remove-files-webpack-plugin","description":"A webpack plugin for removing files and folders before and after compilation. Current stable version is 1.5.0, released 2021-04-12. Supports webpack >= 2.2.0 and Node >= 8.3.0. Ships TypeScript types. Key differentiators: supports before, after, and watch compilation modes; handles symbolic links as ordinary files; works on all OS with platform-specific path handling. Unlike clean-webpack-plugin, it allows granular control over which files to remove and supports watch mode cleanup. Development appears dormant since 2021.","status":"maintenance","version":"1.5.0","language":"javascript","source_language":"en","source_url":"https://github.com/Amaimersion/remove-files-webpack-plugin","tags":["javascript","webpack","webpack-plugin","webpack-compilation","webpack-files","compilation","plugin","files","build-automation","typescript"],"install":[{"cmd":"npm install remove-files-webpack-plugin","lang":"bash","label":"npm"},{"cmd":"yarn add remove-files-webpack-plugin","lang":"bash","label":"yarn"},{"cmd":"pnpm add remove-files-webpack-plugin","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency; plugin integrates with webpack compilation hooks","package":"webpack","optional":false}],"imports":[{"note":"Package does not ship ESM exports; only CommonJS is supported. TypeScript users may use `import RemovePlugin = require('remove-files-webpack-plugin')` for compatibility.","wrong":"import RemovePlugin from 'remove-files-webpack-plugin';","symbol":"RemovePlugin","correct":"const RemovePlugin = require('remove-files-webpack-plugin');"},{"note":"Use TypeScript import equals syntax for correct type resolution. The named import pattern is not supported.","wrong":"import { RemovePlugin } from 'remove-files-webpack-plugin';","symbol":"RemovePlugin","correct":"import RemovePlugin = require('remove-files-webpack-plugin');"},{"note":"The plugin expects a configuration object with `before`, `watch`, or `after` namespaces, not flat options.","wrong":"new RemovePlugin({ include: ['dist'] })","symbol":"RemovePlugin","correct":"new RemovePlugin({ before: { include: ['dist'] } })"}],"quickstart":{"code":"const RemovePlugin = require('remove-files-webpack-plugin');\n\nmodule.exports = {\n  context: __dirname,\n  entry: './src/index.js',\n  output: { path: './dist', filename: 'bundle.js' },\n  plugins: [\n    new RemovePlugin({\n      before: {\n        include: ['./dist'],\n        allowRoot: false\n      },\n      after: {\n        include: ['./dist/temp']\n      }\n    })\n  ]\n};","lang":"javascript","description":"Demonstrates removing the 'dist' folder before compilation and a 'temp' folder after compilation using the before and after namespaces."},"warnings":[{"fix":"Wrap options in the appropriate namespace: `new RemovePlugin({ before: { include: [...] } })`.","message":"Plugin configuration must be nested under `before`, `watch`, or `after` namespaces; flat configuration with `include` at root will be silently ignored.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Set the `root` option explicitly or use absolute paths.","message":"Paths in `include` and `exclude` are resolved relative to the plugin's `root` option (defaults to webpack's context, typically `.`). Do not assume they are relative to the project root.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Explicitly set `root: process.cwd()` if the previous behavior was desired.","message":"Version 1.4.0 changed the default root from the current working directory to the webpack context (process.cwd()). Projects relying on the old default may delete the wrong files.","severity":"breaking","affected_versions":"1.4.0 - 1.5.0"},{"fix":"Avoid using `allowRoot: true`; ensure `include` and `exclude` paths are subdirectories of `root`.","message":"The `allowRoot` option (default `false`) is deprecated and may be removed in a future major version.","severity":"deprecated","affected_versions":">=1.3.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Wrap options: `new RemovePlugin({ before: { include: ['dist'] } })`.","cause":"Passing flat configuration like `new RemovePlugin({ include: ['dist'] })`.","error":"Error: The plugin must be constructed with an object containing 'before', 'watch', or 'after' namespaces."},{"fix":"Upgrade to webpack 5 compatible version of the plugin or use webpack 4.","cause":"Using an unsupported webpack version (e.g., webpack 5 without compatibility layer).","error":"Cannot read property 'tapAsync' of undefined"},{"fix":"Provide at least one namespace: `new RemovePlugin({ after: { include: [] } })`.","cause":"Omitting the options object entirely (e.g., `new RemovePlugin()`) or passing `null`.","error":"TypeError: Cannot read property 'root' of undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}