{"id":20726,"library":"webpack-common-shake","title":"webpack-common-shake","description":"Webpack plugin for tree-shaking CommonJS modules. Version 2.1.0 is the latest stable release, published in 2019. It removes unused assignments to exports properties, leaving dead code elimination to UglifyJS. Unlike ES module tree-shaking, this targets CommonJS exports. Works with Webpack 4+; for Webpack 3 use version 1.x. Provides options for warnings and bailout callbacks. Notable limitations: dynamic exports, dynamic require, and certain re-assignments cause bailouts.","status":"maintenance","version":"2.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/indutny/webpack-common-shake","tags":["javascript","webpack","commonjs","tree","shake"],"install":[{"cmd":"npm install webpack-common-shake","lang":"bash","label":"npm"},{"cmd":"yarn add webpack-common-shake","lang":"bash","label":"yarn"},{"cmd":"pnpm add webpack-common-shake","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core tree-shaking algorithm for CommonJS modules","package":"common-shake","optional":false},{"reason":"Peer dependency: Webpack 4+ required","package":"webpack","optional":false}],"imports":[{"note":"CommonJS module; does not support ESM imports. Use require or dynamic import().","wrong":"import { Plugin } from 'webpack-common-shake';","symbol":"ShakePlugin","correct":"const { ShakePlugin } = require('webpack-common-shake');"},{"note":"Named export, not default.","wrong":"import ShakePlugin from 'webpack-common-shake';","symbol":"Plugin","correct":"const ShakePlugin = require('webpack-common-shake').Plugin;"},{"note":"Works in ESM context, but package is CJS; dynamic import also possible.","wrong":"const { ShakePlugin } = require('webpack-common-shake');","symbol":"ShakePlugin","correct":"import { ShakePlugin } from 'webpack-common-shake';"}],"quickstart":{"code":"const ShakePlugin = require('webpack-common-shake').Plugin;\n\nmodule.exports = {\n  entry: './src/index.js',\n  output: {\n    path: __dirname + '/dist',\n    filename: 'bundle.js'\n  },\n  plugins: [\n    new ShakePlugin({\n      warnings: { global: true, module: false },\n      onExportDelete: (resource, property) => {\n        console.log(`Deleted ${property} from ${resource}`);\n      },\n      onModuleBailout: (module, bailouts) => {\n        console.warn(`Bailout for ${module}: ${bailouts.join(', ')}`);\n      },\n      onGlobalBailout: (bailouts) => {\n        console.warn(`Global bailout: ${bailouts.join(', ')}`);\n      }\n    })\n  ]\n};","lang":"javascript","description":"Basic Webpack 4+ configuration with ShakePlugin, including optional callbacks for export deletion and bailouts."},"warnings":[{"fix":"Use webpack-common-shake@1.x with Webpack 3, or upgrade to Webpack 4+.","message":"Plugin must be used with Webpack 4+; Webpack 3 requires version 1.x.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Avoid dynamic property access on exports. Use static export assignments.","message":"Dynamic exports like exports[Math.random()] cause module bailout; tree-shaking disabled for that module.","severity":"gotcha","affected_versions":">=0"},{"fix":"Do not reassign variables that hold required modules.","message":"Overriding required module variable (e.g., var a = require('./a'); a = require('./b')) causes bailout.","severity":"gotcha","affected_versions":">=0"},{"fix":"Assign require result to a variable before using.","message":"Using require in non-standard ways (e.g., console.log(require('./lib'))) may cause bailout.","severity":"gotcha","affected_versions":">=0"},{"fix":"Use static import paths and access properties directly.","message":"Dynamic import like require('./lib')[Math.random()] causes bailout.","severity":"gotcha","affected_versions":">=0"},{"fix":"Avoid dynamic require expressions.","message":"Dynamic require (e.g., require(Math.random())) causes global bailout; plugin disabled entirely.","severity":"gotcha","affected_versions":">=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-common-shake --save-dev","cause":"Package not installed or wrong import path.","error":"Cannot find module 'webpack-common-shake'"},{"fix":"const ShakePlugin = require('webpack-common-shake').Plugin;","cause":"Incorrect import: using default import instead of named export.","error":"ShakePlugin is not a constructor"},{"fix":"Upgrade to Webpack 4+ or use webpack-common-shake@1.x.","cause":"Webpack version incompatible (<4).","error":"Module parse failed: Unexpected token (1:0)"},{"fix":"Remove dynamic require or use onGlobalBailout to handle.","cause":"Dynamic require call in code.","error":"Bailout: dynamic require detected"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}