Webpack Deduplication Plugin
raw JSON → 0.0.8 verified Sat Apr 25 auth: no javascript
Webpack plugin that deduplicates transitive dependencies in yarn and webpack-based projects. Version 0.0.8 (stable, low release cadence) by Atlassian Labs. Uses content-based caching via yarn.lock to avoid duplicate modules. Differentiator: targeted at monorepo or complex dependency trees where multiple versions of the same package are bundled, reducing bundle size. Compared to alternatives like DedupePlugin, this plugin persists cache across builds and integrates tightly with yarn workspace resolution. Currently in early development; lacking documentation and tests.
Common errors
error TypeError: Cannot read property 'context' of undefined ↓
cause WebpackDeduplicationPlugin expects a webpack compiler object with context; misconfigured plugin order.
fix
Ensure plugin is added to plugins array after other plugins that modify compiler context, or set rootPath explicitly.
error Error: ENOENT: no such file or directory, open '.../yarn.lock' ↓
cause Plugin cannot find yarn.lock because rootPath is incorrect or project uses npm/pnpm.
fix
Provide correct rootPath or ensure a yarn.lock file exists at the root; plugin currently only supports yarn.
error Module not found: Error: Can't resolve 'app-root-path' ↓
cause app-root-path is an optional dependency; if missing and rootPath not provided, plugin throws.
fix
Install app-root-path as a dev dependency or provide rootPath explicitly.
Warnings
gotcha Plugin is experimental; may not handle all edge cases in dependency deduplication. ↓
fix Test thoroughly in your project; contribute fixes if issues arise.
gotcha cacheDir is not cleaned automatically; stale cache may cause incorrect deduplication after dependency changes. ↓
fix Manually delete cacheDir when yarn.lock changes or dependencies update.
gotcha Plugin requires webpack 4 or 5; not tested with other bundlers. ↓
fix Use only with webpack 4+; check compatibility with your webpack version.
Install
npm install webpack-deduplication-plugin yarn add webpack-deduplication-plugin pnpm add webpack-deduplication-plugin Imports
- WebpackDeduplicationPlugin wrong
const WebpackDeduplicationPlugin = require('webpack-deduplication-plugin').defaultcorrectimport { WebpackDeduplicationPlugin } from 'webpack-deduplication-plugin'
Quickstart
// webpack.config.js
const path = require('path');
const { WebpackDeduplicationPlugin } = require('webpack-deduplication-plugin');
const cacheDirPath = path.resolve(__dirname, '.cache/webpack-deduplication');
const rootPath = path.resolve(__dirname, '.');
module.exports = {
context: __dirname,
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js',
},
plugins: [
new WebpackDeduplicationPlugin({
cacheDir: cacheDirPath,
rootPath: rootPath,
}),
],
};