rollup-plugin-analyzer
raw JSON → 4.0.0 verified Mon Apr 27 auth: no javascript
Rollup plugin that prints detailed bundle analysis metrics to the console, including bundle size, original size, code reduction percentage, module count, and per-file breakdown with rendered size, original size, relative contribution, and dependents. Version 4.0.0 supports Rollup 2.x/3.x. Outputs formatted tables and optional summary-only view. Useful for CI gating via onAnalysis callback. Differentiators include zero dependencies, optional CI integration, and summaryOnly mode for concise output.
Common errors
error Error [ERR_REQUIRE_ESM]: require() of ES Module [...] from [...] not supported. ↓
cause Node.js trying to require an ESM module when using require() with type: 'module' or .mjs files.
fix
Use import instead of require() in your rollup config, or rename file to .cjs.
error TypeError: analyze is not a function ↓
cause Using named import { analyze } instead of default import.
fix
Use: import analyze from 'rollup-plugin-analyzer' (no braces).
error Error: Cannot find module 'rollup-plugin-analyzer' ↓
cause Package not installed or not in node_modules.
fix
Run: npm install --save-dev rollup-plugin-analyzer
Warnings
breaking Version 4.0.0 drops support for Rollup < 2.x. Ensure you are using Rollup 2 or higher. ↓
fix Upgrade to Rollup 2.x or later, or pin to rollup-plugin-analyzer@3.x.
gotcha The module counts rendered size (after tree-shaking), not original size. Be aware when comparing numbers. ↓
fix Read documentation: rendered size is post-tree-shaking; original size is before.
deprecated The `entry` and `dest` options in the example are for Rollup < 1.x. Modern Rollup uses `input` and `output`. ↓
fix Use `input` and `output` per Rollup 1.x+ API. Example in README may be outdated.
gotcha If using ESM in Node.js (e.g., type: 'module'), ensure your config file uses .mjs extension or dynamic import for CJS plugins. ↓
fix Rename config to rollup.config.mjs or use createRequire from 'module'.
Install
npm install rollup-plugin-analyzer yarn add rollup-plugin-analyzer pnpm add rollup-plugin-analyzer Imports
- default (analyze) wrong
import { analyze } from 'rollup-plugin-analyzer'correctimport analyze from 'rollup-plugin-analyzer' - default (analyze) via require
const analyze = require('rollup-plugin-analyzer') - onAnalysis callback wrong
import { onAnalysis } from 'rollup-plugin-analyzer'correctimport analyze from 'rollup-plugin-analyzer'; analyze({ onAnalysis: ({ bundleSize }) => { /* ... */ } })
Quickstart
// rollup.config.js
import analyze from 'rollup-plugin-analyzer';
export default {
input: 'src/index.js',
output: {
file: 'dist/bundle.js',
format: 'cjs'
},
plugins: [
analyze({
summaryOnly: true,
limit: 10,
filter: (module) => !module.includes('node_modules'),
onAnalysis: ({ bundleSize, moduleCount }) => {
console.log(`Bundle size: ${bundleSize} bytes, modules: ${moduleCount}`);
}
})
]
};