rollup-dependency-tree

raw JSON →
0.0.14 verified Mon Apr 27 auth: no javascript

A utility library (v0.0.14) that builds a transitive dependency tree from Rollup's OutputChunk array, enabling preloading of JavaScript imports. Designed for Sapper/SvelteKit ecosystems but usable with any Rollup build. Differentiates from general dependency analyzers by working directly with Rollup's output format. Infrequent releases; appears stable within narrow scope. Ships TypeScript types.

error TypeError: generateDependencyTree is not a function
cause Using CJS require on an ESM-only package.
fix
Use import statement or dynamic import().
error Cannot read properties of undefined (reading 'module')
cause Passing entire bundle object instead of output array.
fix
Pass output.output (the array of OutputChunk).
error The tree does not include all imports
cause Dynamic imports or non-JS imports (CSS, images) are not processed.
fix
Only static JS imports are captured; other types are ignored.
gotcha Input must be Rollup OutputChunk[], not OutputAsset[] or complete bundle.
fix Ensure you pass output.output (the array of chunks) from bundle.generate/write.
gotcha Only handles static import statements; dynamic imports (import()) are not included in the tree.
fix Use a separate analyzer for dynamic imports or modify the library.
gotcha Tree may include external dependencies (node_modules) if not excluded by Rollup config.
fix Configure Rollup's `inlineDynamicImports` or external to filter nodes.
deprecated Original Sapper integration is deprecated; SvelteKit uses a different mechanism.
fix For SvelteKit, use built-in preloading instead.
npm install rollup-dependency-tree
yarn add rollup-dependency-tree
pnpm add rollup-dependency-tree

Demonstrates how to generate a dependency tree from a Rollup build output using the main export.

import { generateDependencyTree } from 'rollup-dependency-tree';

// Assume `output` is the result of rollup.generate() or rollup.write()
import { rollup } from 'rollup';

async function main() {
  const bundle = await rollup({
    input: 'src/main.js'
  });
  const { output } = await bundle.generate({ format: 'es' });
  
  const tree = generateDependencyTree(output);
  console.log(JSON.stringify(tree, null, 2));
}

main().catch(console.error);