rollup-plugin-extract-bundle-tree
raw JSON → 1.2.0 verified Mon Apr 27 auth: no javascript
Rollup plugin (v1.2.0) that exports the bundle module tree as a JSON file for analysis or visualization. It provides per-file information including chunk name, entry/dynamic entry flags, asset detection, imports, and dynamic imports. The plugin is lightweight and has no dependencies beyond Rollup >=1.9.0. It is ideal for build pipeline introspection, dependency mapping, or custom tooling.
Common errors
error Error [ERR_REQUIRE_ESM]: require() of ES Module not supported ↓
cause Using CommonJS require() to import the ESM-only package.
fix
Use import syntax or set type: 'module' in package.json, or use dynamic import().
error TypeError: bundleTree is not a function ↓
cause Using named import { bundleTree } instead of default import.
fix
Use import bundleTree from 'rollup-plugin-extract-bundle-tree'.
error Error: Cannot find module 'rollup' ↓
cause Missing peer dependency rollup.
fix
Install rollup: npm install --save-dev rollup.
Warnings
gotcha The plugin outputs a JSON file containing all modules, including assets. Assets are only identified by `isAsset: true`; the `chunkName` field may be absent for assets. ↓
fix When parsing output, check for the existence of `chunkName` before using it or rely on `isAsset` flag.
gotcha The `assetImports` field in the output only appears for chunks that import assets; it is not present for all entries. This can cause confusion when iterating over the tree. ↓
fix Treat `assetImports` as optional and default to an empty array if missing.
breaking Removed Node.js 10 and 12 support; requires Node >=14. ↓
fix Upgrade Node.js to version 14 or higher.
Install
npm install rollup-plugin-extract-bundle-tree yarn add rollup-plugin-extract-bundle-tree pnpm add rollup-plugin-extract-bundle-tree Imports
- bundleTree wrong
const bundleTree = require('rollup-plugin-extract-bundle-tree')correctimport bundleTree from 'rollup-plugin-extract-bundle-tree' - bundleTree wrong
import { bundleTree } from 'rollup-plugin-extract-bundle-tree'correctimport bundleTree from 'rollup-plugin-extract-bundle-tree' - bundleTree options
bundleTree({ file: 'tree.json' })
Quickstart
// rollup.config.js
import bundleTree from 'rollup-plugin-extract-bundle-tree';
export default {
input: 'src/index.js',
output: { dir: 'dist', format: 'esm' },
plugins: [
bundleTree({ file: 'bundle-tree.json' })
]
}