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
npm list
Prints the installed dependency tree of the current project (or globally). Aliases: `ls`, `la`, `ll`.
npm outdated
Compares installed versions against the registry and reports which packages have a newer version available in current/wanted/latest columns. `wanted` respects your semver range, `latest` is the newest published.
npm view (info)
Fetches package metadata straight from the registry — versions, maintainers, dist-tags, dependencies, and more. Aliases: `info`, `show`, `v`.