{"id":20738,"library":"webpack-deadcode-plugin","title":"webpack-deadcode-plugin","description":"Webpack plugin (v0.1.17) that detects unused files and unused exports in used files during the webpack build process. It outputs warnings to the terminal without failing the build unless configured otherwise. Works with webpack 3, 4, and 5 via peer dependency. Key differentiators: supports both file and export detection, integrates with TypeScript loaders (with caveats), offers granular logging and JSON export. Active development with periodic releases.","status":"active","version":"0.1.17","language":"javascript","source_language":"en","source_url":"https://github.com/MQuy/webpack-deadcode-plugin","tags":["javascript","webpack","plugin","unused","deadcode"],"install":[{"cmd":"npm install webpack-deadcode-plugin","lang":"bash","label":"npm"},{"cmd":"yarn add webpack-deadcode-plugin","lang":"bash","label":"yarn"},{"cmd":"pnpm add webpack-deadcode-plugin","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency; plugin architecture ties to webpack's compilation hooks","package":"webpack","optional":false}],"imports":[{"note":"Package uses CommonJS exports; ESM import may fail without a bundler. Use require() in Node.js or webpack config.","wrong":"import DeadCodePlugin from 'webpack-deadcode-plugin';","symbol":"DeadCodePlugin","correct":"const DeadCodePlugin = require('webpack-deadcode-plugin');"},{"note":"The module exports a single constructor function directly, not as a named export. Destructuring will yield undefined.","wrong":"const { DeadCodePlugin } = require('webpack-deadcode-plugin');","symbol":"undefined","correct":"const DeadCodePlugin = require('webpack-deadcode-plugin');"},{"note":"Must be called with 'new' and an options object; calling without 'new' will throw.","wrong":"DeadCodePlugin()","symbol":"DeadCodePlugin","correct":"new DeadCodePlugin({ ...options })"}],"quickstart":{"code":"// webpack.config.js\nconst DeadCodePlugin = require('webpack-deadcode-plugin');\n\nmodule.exports = {\n  entry: './src/index.js',\n  output: { filename: 'bundle.js' },\n  plugins: [\n    new DeadCodePlugin({\n      patterns: ['src/**/*.(js|jsx|css)'],\n      exclude: ['**/*.(stories|spec).(js|jsx)'],\n      failOnHint: true,\n    }),\n  ],\n};","lang":"javascript","description":"Basic webpack config with deadcode plugin to detect unused files/exports."},"warnings":[{"fix":"In .babelrc: { \"presets\": [[\"env\", { \"modules\": false }]] } or in webpack config: { loader: 'babel-loader', options: { presets: [['env', { modules: false }]] } }","message":"When using babel-loader, must set modules: false in .babelrc or babel-loader options to prevent module transformation that would break dead code detection.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Disable transpileOnly or switch to awesome-typescript-loader for production.","message":"With TypeScript loaders (ts-loader, awesome-typescript-loader), enabling transpileOnly/happyPackMode may produce incorrect output due to ts-loader issue #783.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Upgrade to v0.1.13 or later for webpack 5 compatibility.","message":"The plugin was originally designed for webpack 3 and 4; webpack 5 support was added in v0.1.13, but users must ensure version compatibility.","severity":"breaking","affected_versions":"<0.1.13"},{"fix":"Add failOnHint: true to options if you want the build to error out.","message":"The plugin outputs warnings only and does not fail the build by default. To fail on unused code, set failOnHint: true.","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":"npm install webpack-deadcode-plugin --save-dev","cause":"Package not installed or CommonJS require used in ESM module context.","error":"Cannot find module 'webpack-deadcode-plugin'"},{"fix":"Use: const DeadCodePlugin = require('webpack-deadcode-plugin'); new DeadCodePlugin(options);","cause":"Missing 'new' keyword or destructured import incorrectly.","error":"TypeError: DeadCodePlugin is not a constructor"},{"fix":"Ensure patterns match your source files, e.g., patterns: ['src/**/*.(js|jsx|ts|tsx|css)']","cause":"Patterns option too restrictive or exclude option incorrectly set.","error":"Unused files not reported"},{"fix":"Set modules: false in babel presets as described in documentation.","cause":"Babel transforms modules and loses tracking. Need modules: false.","error":"Unused exports not detected when using babel"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}