inspect

npm why (explain)

Prints the dependency chain(s) that caused a specific package (or version) to be installed. Alias: `why`; invaluable for tracking down duplicate copies or unexpected transitive deps.

npm explain <pkg>[@<version>]

Common flags

Flag Purpose
--json Emit the explanation as JSON
--workspace <name> Explain within a specific workspace

Examples

npm why lodash

Show every path in the tree that pulls in lodash

npm explain react@17

Explain why an older react version is present

npm why glob --json

Get the reason chain as JSON for tooling

Gotcha

`why` only reports packages already installed in node_modules — run `npm install` first if you are debugging a fresh clone. Pair with `npm dedupe` to eliminate duplicates it uncovers.

Related commands

← All npm commands · npm vs pnpm vs Yarn · Fix Node OOM