Registry / devops / webpack-deadcode-plugin

webpack-deadcode-plugin

JSON →
library0.1.17jsnpmunverified

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.

npm install webpack-deadcode-plugin
INSTALL
IMPORT
SIG · WEBPACK-DEADCODE-P
W
webpack-deadcode-plugin
devopsjavascriptv0.1.17
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
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 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

DeadCodePlugin
✓ const DeadCodePlugin = require('webpack-deadcode-plugin');
✗ import DeadCodePlugin from 'webpack-deadcode-plugin';
Package uses CommonJS exports; ESM import may fail without a bundler. Use require() in Node.js or webpack config.
undefined
✓ const DeadCodePlugin = require('webpack-deadcode-plugin');
✗ const { DeadCodePlugin } = require('webpack-deadcode-plugin');
The module exports a single constructor function directly, not as a named export. Destructuring will yield undefined.
DeadCodePlugin
✓ new DeadCodePlugin({ ...options })
✗ DeadCodePlugin()
Must be called with 'new' and an options object; calling without 'new' will throw.

Basic webpack config with deadcode plugin to detect unused files/exports.

// webpack.config.js const DeadCodePlugin = require('webpack-deadcode-plugin'); module.exports = { entry: './src/index.js', output: { filename: 'bundle.js' }, plugins: [ new DeadCodePlugin({ patterns: ['src/**/*.(js|jsx|css)'], exclude: ['**/*.(stories|spec).(js|jsx)'], failOnHint: true, }), ], };
Debug
Known issues
gotchaWhen using babel-loader, must set modules: false in .babelrc or babel-loader options to prevent module transformation that would break dead code detection.
fix
In .babelrc: { "presets": [["env", { "modules": false }]] } or in webpack config: { loader: 'babel-loader', options: { presets: [['env', { modules: false }]] } }
affects: >=0.0.0
gotchaWith TypeScript loaders (ts-loader, awesome-typescript-loader), enabling transpileOnly/happyPackMode may produce incorrect output due to ts-loader issue #783.
fix
Disable transpileOnly or switch to awesome-typescript-loader for production.
affects: >=0.0.0
breakingThe plugin was originally designed for webpack 3 and 4; webpack 5 support was added in v0.1.13, but users must ensure version compatibility.
fix
Upgrade to v0.1.13 or later for webpack 5 compatibility.
affects: <0.1.13
gotchaThe plugin outputs warnings only and does not fail the build by default. To fail on unused code, set failOnHint: true.
fix
Add failOnHint: true to options if you want the build to error out.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'webpack-deadcode-plugin'
Package not installed or CommonJS require used in ESM module context.
fix
npm install webpack-deadcode-plugin --save-dev
TypeError: DeadCodePlugin is not a constructor
Missing 'new' keyword or destructured import incorrectly.
fix
Use: const DeadCodePlugin = require('webpack-deadcode-plugin'); new DeadCodePlugin(options);
Unused files not reported
Patterns option too restrictive or exclude option incorrectly set.
fix
Ensure patterns match your source files, e.g., patterns: ['src/**/*.(js|jsx|ts|tsx|css)']
Unused exports not detected when using babel
Babel transforms modules and loses tracking. Need modules: false.
fix
Set modules: false in babel presets as described in documentation.
Upgrade
Version history
0.1.17latest on npm
Audit
Dependencies
webpackrequiredPeer dependency; plugin architecture ties to webpack's compilation hooks
Agent activity
17 hits · last 30 days
node
16
Resources
webpack-deadcode-plugin — npm install webpack-deadcode-plugin · libregistry