- "Why is package X installed?" has a built-in answer in most ecosystems:
npm explain,pnpm why,yarn why,go mod why,cargo tree -i,pipdeptree --reverseandgradle dependencyInsight.[1][2][4] - Circular imports are a different problem from package trees. Use
madge --circularor the no-circular rule that dependency-cruiser adds when you run its init command.[5][6] - Pipe graph output to Graphviz for a picture. madge, dependency-cruiser, pipdeptree and
mvn dependency:treecan all emit DOT or SVG. - For licences, use
pnpm licenses list,npm sbomorpipdeptree --summaryrather than reading trees by eye. - GitHub's dependency graph and deps.dev show the same data in a browser, including dependents and advisories, without checking out the code.[14][15]
You do not need to install a separate dependency viewer: npm, pnpm, Yarn, uv, Cargo, Go, Maven and Gradle each ship a command that prints the dependency tree, and two small tools, madge and dependency-cruiser, draw module-level graphs. The commands differ by question: "what is installed" is a tree, "why is this here" is a reverse path, and "who imports whom" is a module graph. This post gives the exact command for each case, with flags checked against the official documentation on 18 October 2026, then covers GitHub's dependency graph and deps.dev for the hosted view.
Which command answers which question
Start from the question, not the tool. Package managers resolve a lockfile into a tree; module-graph tools read your source imports. The table maps the four questions people actually ask to the command in each ecosystem.
| Question | JavaScript | Python | Rust and Go | JVM |
|---|---|---|---|---|
| Who depends on X? | npm ls X, pnpm why X, yarn why X | pipdeptree --reverse --packages X, uv tree --invert --package X | cargo tree -i X; go mod graph filtered with grep | mvn dependency:tree -Dincludes=... |
| Why is X installed? | npm explain X, pnpm why X | pipdeptree --reverse | go mod why -m X, cargo tree -i X | gradle dependencyInsight --dependency X |
| Which versions of X are present? | npm ls X | pipdeptree (flags conflicts) | cargo tree -d, go list -m all | gradle dependencyInsight (selection reasons) |
| Circular imports? | madge --circular, dependency-cruiser | not covered here | not covered here | not covered here |
| Licence audit? | pnpm licenses list, npm sbom | pipdeptree --summary | not covered here | not covered here |
Circular-import detection and licence reports in Rust, Go and the JVM exist as separate tools; we did not verify them against primary documentation for this post, so they are left out rather than guessed.
JavaScript and TypeScript
npm: ls and explain
npm ls prints installed packages in a tree. Without flags it shows only your direct dependencies; adding --all expands the full tree.[1] Give it a package name and it limits the output to the paths leading to that package, including nested copies.[1] The reverse view is npm explain (alias npm why), which prints the chain of dependencies that caused a package to be installed.[1][2]
npm ls --all # full tree from node_modules
npm ls --all --omit=dev # production dependencies only
npm ls --package-lock-only # read package-lock.json, not node_modules
npm ls glob # every path that leads to glob
npm explain glob # the chain that caused glob to be installed
npm ls --all --json > tree.json # machine-readable outputTwo details from the documentation matter in practice. --omit accepts dev, optional or peer and can be repeated, and --package-lock-only makes npm ls work from the lockfile, which is useful in CI where you have not installed anything.[1]
pnpm: list and why
pnpm list (alias ls) defaults to --depth 0, direct dependencies only; --depth Infinity lists everything, and --prod or --dev filters by dependency type.[3] pnpm why prints a reverse dependency tree with the searched package at the root and its dependents as branches, deduplicating repeated subtrees.[3] In a workspace, add -r to run across every project.
pnpm list --depth Infinity --prod
pnpm why glob
pnpm why glob -r --json # every workspace project, as JSON
pnpm list --lockfile-only # read the lockfile (added in pnpm v10.23.0)Yarn: why
The command is the same on both major lines. yarn why lodash explains why a package is in the tree, and you can pass a version or range to find out why an old version is still there. In Yarn 2 and later, -R (--recursive) lists, for each workspace, every path that leads to the dependency, and --peers also prints matching peer dependencies.[4]
yarn why lodash
yarn why -R lodash # Yarn 2+ : every path, per workspacemadge and dependency-cruiser: module-level graphs
Package managers know packages. They cannot tell you that src/a.ts imports src/b.ts which imports src/a.ts. For that you need a tool that reads your source. Both of these are Node tools and both draw graphs through Graphviz, so install Graphviz first if you want images (brew install graphviz or apt-get install graphviz).[5]
madge generates a graph of module dependencies and finds circular ones. Its README documents these invocations:[5]
npx madge --extensions ts,tsx --circular src/ # list circular dependencies
npx madge --extensions ts,tsx --image graph.svg src/app.ts
npx madge --circular --image cycles.svg src/app.js # only the cycles
npx madge --depends wheels.js src/app.js # who depends on a module
npx madge --orphans src/ # modules nobody imports
npx madge --dot src/app.js > graph.gv # DOT for further processingdependency-cruiser validates dependencies against rules and renders them. Running npx dependency-cruiser --init writes a config that, per the README, includes rules for circular dependencies, dependencies missing from package.json, orphans, and production code that relies on dev dependencies.[6] The CLI documentation lists no-circular among the rules --init writes, and describes a --reaches option that shows a module together with everything that can reach it, directly or indirectly, which answers "what breaks if I change this file".[7]
npx dependency-cruiser --init
npx dependency-cruiser src --include-only "^src" --output-type dot | dot -T svg > dependency-graph.svg
npx dependency-cruiser src --include-only "^src/report" \
--reaches "^src/report/utl/index.js" -T dot | dot -T svg > reaches.svgThe rule engine is the reason to pick dependency-cruiser over madge for CI: once --init has written .dependency-cruiser.js, a plain run validates against it (since version 13 the config file is picked up by default).[7] madge is quicker for a one-off "show me the cycles" check.
Python
pipdeptree
pipdeptree displays installed Python packages as a dependency tree. Where pip freeze prints a flat list, it adds parent-child relationships and reports conflicts and cycles.[8] The current PyPI release lists Python 3.11 or newer as a requirement, so on an older interpreter use uv tree instead.[8]
pip install pipdeptree
pipdeptree # full tree with conflicts flagged
pipdeptree --reverse --packages markupsafe # who requires markupsafe
pipdeptree -o json
pipdeptree -o mermaid
pipdeptree -o graphviz-svg > deps.svg
pipdeptree --summary # counts, depth, conflicts, cycles, licenses, sizeIts README also documents pipdeptree from-index "flask" to inspect a tree without installing it, and -o cyclonedx-json to export a CycloneDX SBOM.[8]
uv tree
If the project uses uv, uv tree displays the project's dependency tree. The CLI reference lists --depth (default 255), --invert (also --reverse, which shows the packages that depend on a given package), --package to display only specific packages, --outdated to show each package's latest available version, and --universal for a platform-independent tree.[9]
uv tree
uv tree --depth 2
uv tree --invert --package urllib3
uv tree --outdated
uv tree --universalRust, Go and the JVM
cargo tree
cargo tree displays the tree and marks packages whose subtree was already shown with (*); --no-dedupe repeats them. The options that matter: -i spec inverts the tree to show reverse dependencies, -d shows only packages that appear in multiple versions (it implies --invert), --depth caps the depth, and -e features displays which features each dependency enables.[10]
cargo tree --depth 1
cargo tree -i log # who depends on log
cargo tree -d # packages built in more than one version
cargo tree -e features -i log # how features flow into loggo mod graph and go mod why
go mod graph prints the module requirement graph, one edge per line, with replacements applied. Each vertex is a specific module version and each edge a requirement on a minimum version.[11] go mod why shows a shortest path in the import graph from the main module to each listed package, or a parenthesised note if nothing references it. -m treats the arguments as modules rather than packages.[11]
go mod graph | grep " golang.org/x/text@" # lines whose second column is x/text
go mod why -m golang.org/x/text
go list -m all # selected versions of every moduleMaven
The dependency plugin's tree goal prints the tree. It takes includes and excludes filters in the form groupId:artifactId:type:version with wildcards, a verbose flag to include omitted nodes, outputFile to write to a path, and outputType with text (default), dot, graphml, tgf or json (json since 3.7.0).[12]
mvn dependency:tree
mvn dependency:tree -Dincludes=commons-codec:commons-codec -Dverbose
mvn dependency:tree -DoutputType=dot -DoutputFile=deps.dot
dot -Tsvg deps.dot -o deps.svgGradle
Gradle's built-in dependencies task renders the tree for all configurations in a project; --configuration narrows it to one, and abbreviated names such as tRC for testRuntimeClasspath work when they are unambiguous.[13] dependencyInsight explains one dependency: it takes --dependency (a full group:name or part of it) and --configuration, and reports why that version was selected, including conflict resolution.[13]
./gradlew -q dependencies --configuration testRuntimeClasspath
./gradlew -q dependencyInsight --dependency commons-codec --configuration runtimeClasspathHosted viewers: GitHub and deps.dev
GitHub's dependency graph is a summary of the manifest and lock files in a repository, plus anything submitted through the dependency submission API. For each repository it lists dependencies and dependents; for each dependency it shows the version, licence information, the manifest file that declared it and whether it has known vulnerabilities. For ecosystems with transitive support, you can expand a row and choose "Show paths" to see the chain that brought it in. It is on by default for public repositories and also available for private repositories and forks.[14]
deps.dev (Open Source Insights) works from the package side. Its website lets you search open-source packages, visualise dependencies, compare versions and investigate security advisories, and the same data is available through an HTTP and gRPC API and a BigQuery dataset.[15] Reach for it when you are judging a package you have not installed yet.
Paste-a-manifest viewer
If you only need a picture and have no shell open, the Codebase Dependency Visualizer accepts a pasted package.json, requirements.txt, go.mod or Cargo.toml and draws the dependencies as an interactive graph with click-to-inspect nodes and SVG export. It graphs what the manifest you paste declares, so a fully resolved transitive tree still comes from the commands above. Run the command with --json or -o json, then tidy the output in the JSON Formatter if you need to read it by eye.
Tools at a glance
| Tool | Ecosystem | Reads | Graph output | Best for |
|---|---|---|---|---|
npm ls / npm explain | npm | node_modules or lockfile | Text tree, JSON | Paths to a package |
pnpm list / pnpm why | pnpm | node_modules or lockfile | Text tree, JSON, parseable | Workspaces |
yarn why | Yarn | Resolved install | Text, NDJSON in Yarn 2+ | Old versions that linger |
| madge | JS, TS (module imports) | Source files | SVG, DOT, JSON | Quick cycle check |
| dependency-cruiser | JS, TS (module imports) | Source files, config rules | DOT, SVG via Graphviz | CI rules, impact analysis |
pipdeptree / uv tree | Python | Installed packages / lockfile | JSON, Mermaid, SVG | Conflicts, reverse lookups |
cargo tree | Rust | Cargo.lock and manifests | Text tree | Duplicate versions, features |
go mod graph / why | Go | go.mod graph | Edge list | Shortest import path |
mvn dependency:tree | Maven | POMs | Text, DOT, GraphML, TGF, JSON | Filtered trees |
gradle dependencies | Gradle | Build configurations | Text tree | Why a version won |
Licence audits
A tree tells you what is installed, not what it is licensed under. pnpm licenses list lists licences for installed packages, with --json, --dev and --long options.[3] npm sbom generates a Software Bill of Materials for the project in SPDX or CycloneDX format via --sbom-format.[1] pipdeptree's --summary output includes licences.[8] In CI, run one of these on every pull request and diff the result against the base branch with the Diff Checker or your own script. For wiring a check like this into a pipeline, see the Node.js GitHub Actions pipeline guide.
Frequently asked questions
Does the GitHub dependency graph replace running these commands locally?
Not entirely. It is built from manifests, lock files and submitted dependencies, so it reflects what is committed, not what is installed on your machine.[14] Local commands show the resolved result of your actual install, including workspace and platform effects.
Sources
- npm ls, npm CLI documentation (also covers
npm sbomoptions at docs.npmjs.com/cli/v11/commands/npm-sbom) - npm explain, npm CLI documentation
- pnpm why, list and licenses, pnpm documentation (pnpm.io/cli/list, pnpm.io/cli/licenses)
- yarn why, Yarn documentation (Classic: classic.yarnpkg.com/en/docs/cli/why)
- madge README, GitHub
- dependency-cruiser README, GitHub
- dependency-cruiser CLI documentation
- pipdeptree README, GitHub and PyPI
- uv CLI reference, Astral documentation
- cargo tree, The Cargo Book
- Go Modules Reference, go.dev
- dependency:tree, Apache Maven Dependency Plugin
- Viewing and debugging dependencies, Gradle User Manual
- About the dependency graph, GitHub Docs
- deps.dev (Open Source Insights) documentation
Written by
WOWHOW
The WOWHOW team brings 14+ years of production engineering experience. Every tool and product in the catalog is built, tested, and curated in-house.
Monday memo · free
One insight, every Monday. 7am IST.
1 field report, 3 links, 1 tool we actually use. No fluff, no spam.
Beyond the writing
Need production-ready templates?
Free browser tools with no signup, plus premium dev templates and starter kits.
Comments · 0
Beta: comments are stored locally on your device and not visible to other readers.
No comments yet. Be the first to share your thoughts.