npm ls: Inspect the Dependency Tree
npm ls shows what is actually installed and why.
When a build pulls the wrong version, npm ls reveals the resolved tree so you can find which dependency requested it.
Common flags
--depth=0- top-level only--all- full tree<pkg>- show paths to one package--json- structured output
Example in CI
Find every path that pulls in a specific package.
shell
npm ls left-pad --allIn CI
npm ls exits non-zero if the tree is invalid (missing/extraneous deps), which makes it a cheap integrity check after install.
Key takeaways
- Use
npm ls <pkg>to trace a version. --depth=0for a quick top-level view.- Non-zero exit flags a broken tree.