{"id":19398,"library":"bundle-stats","title":"bundle-stats","description":"bundle-stats is an in-depth bundle analyzer for webpack, Rspack, Vite, Rollup, and Rolldown that provides detailed reports on bundle size, assets, modules, and packages. It supports comparing multiple builds side-by-side to identify changes, duplicate packages, and new dependencies. Current stable version is 4.22.1, released in April 2025, with active maintenance and frequent updates. Key differentiators include its cross-bundler support via rollup-plugin-webpack-stats, insights like cache invalidation and initial JS/CSS metrics, and a CLI for CI integration. Ships TypeScript types. Requires Node >= 14.","status":"active","version":"4.22.1","language":"javascript","source_language":"en","source_url":"https://github.com/relative-ci/bundle-stats","tags":["javascript","webpack","bundle-size","bundle-analyzer","bundle-stats","stats","bundle","size","assets","typescript"],"install":[{"cmd":"npm install bundle-stats","lang":"bash","label":"npm"},{"cmd":"yarn add bundle-stats","lang":"bash","label":"yarn"},{"cmd":"pnpm add bundle-stats","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required when used as a webpack plugin (BundleStatsWebpackPlugin) or for analyzing webpack stats.","package":"webpack","optional":true},{"reason":"Required when used with Rollup or Vite via rollup-plugin-webpack-stats.","package":"rollup","optional":true}],"imports":[{"note":"Webpack plugin is exported from 'bundle-stats/webpack' subpath. Default import from 'bundle-stats' is the main CLI function, not the plugin.","wrong":"import BundleStatsWebpackPlugin from 'bundle-stats'","symbol":"BundleStatsWebpackPlugin","correct":"import { BundleStatsWebpackPlugin } from 'bundle-stats/webpack'"},{"note":"The main entry exports a default function for CLI usage. Named export does not exist.","wrong":"import { bundleStats } from 'bundle-stats'","symbol":"bundleStats","correct":"import bundleStats from 'bundle-stats'"},{"note":"Rollup/Vite plugin is exported from 'bundle-stats/rollup' subpath. Not available from the main entry.","wrong":"import rollupPluginBundleStats from 'bundle-stats'","symbol":"rollupPluginBundleStats","correct":"import { rollupPluginBundleStats } from 'bundle-stats/rollup'"}],"quickstart":{"code":"// Generate webpack stats JSON\nnpx webpack --profile --json > stats.json\n\n// Analyze with bundle-stats CLI\nnpx bundle-stats stats.json --output-dir ./bundle-stats\n\n// For multiple builds comparison:\nnpx bundle-stats stats1.json stats2.json --output-dir ./bundle-stats\n\n// Programmatic usage (ESM):\nimport bundleStats from 'bundle-stats';\nconst result = await bundleStats({\n  stats: [{ path: 'stats.json' }],\n  outputDir: './bundle-stats',\n  baseline: false,\n});\nconsole.log(result);","lang":"typescript","description":"Shows how to generate webpack stats JSON, run CLI analysis for single/multiple builds, and use the package programmatically in an ESM TypeScript context."},"warnings":[{"fix":"Use default import: `import bundleStats from 'bundle-stats'`.","message":"The main export is a default function, not a named export. Using `import bundleStats from 'bundle-stats'` is correct, but `import { bundleStats } from 'bundle-stats'` will fail.","severity":"gotcha","affected_versions":">=4.0.0"},{"fix":"Import from 'bundle-stats/webpack'.","message":"Webpack plugin must be imported from 'bundle-stats/webpack', not from the main package. Using `import { BundleStatsWebpackPlugin } from 'bundle-stats'` will give undefined.","severity":"gotcha","affected_versions":">=4.0.0"},{"fix":"Use `import { rollupPluginBundleStats } from 'bundle-stats/rollup'`.","message":"Rollup/Vite plugin is imported from 'bundle-stats/rollup', not from the main package or 'bundle-stats/vite'. There is no separate 'vite' subpath export.","severity":"gotcha","affected_versions":">=4.0.0"},{"fix":"Upgrade Node to >= 14.0.","message":"Dropped support for Node < 14 as of v4. The engines field specifies node >= 14.0.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Pass multiple files: `npx bundle-stats stats1.json stats2.json`.","message":"The `compare` mode via CLI `--compare` flag is deprecated in favor of passing multiple stats files as arguments.","severity":"deprecated","affected_versions":">=4.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run `npm install bundle-stats` and use `import { BundleStatsWebpackPlugin } from 'bundle-stats/webpack'`.","cause":"Package 'bundle-stats' is not installed or import path is wrong (e.g., using 'bundle-stats' without '/webpack' subpath).","error":"Error: Cannot find module 'bundle-stats/webpack'"},{"fix":"Use `import bundleStats from 'bundle-stats'`.","cause":"Using named import `{ bundleStats }` instead of default import.","error":"TypeError: bundleStats is not a function"},{"fix":"Ensure stats file is generated with `npx webpack --profile --json > stats.json` and exists at the given path.","cause":"The CLI argument points to a missing or malformed stats file (must be valid webpack stats JSON).","error":"Error: Stats file stats.json does not exist or is not a valid JSON file"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}