Skip to content
Latchkey

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 --all

In 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=0 for a quick top-level view.
  • Non-zero exit flags a broken tree.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →