npm ls: Usage, Options & Common Errors
Inspect the installed dependency tree.
npm ls (alias npm list) prints the resolved dependency tree, so you can see exactly which version of a package is installed and who pulled it in.
What it does
Renders node_modules as a tree from package.json. By default it shows top-level deps; --all shows the full tree. Passing a package name shows just that package and its paths. It exits non-zero when the tree has missing or invalid (unmet) dependencies.
Common usage
npm ls react # where does react resolve, and which version
npm ls --all # full tree
npm ls --depth=1 # limit depth
npm ls --omit=dev # production tree onlyCommon CI gotcha: npm ls exits 1 on invalid tree
A diagnostic step running npm ls fails the job with "npm error code ELSPROBLEMS / invalid: ...". npm ls returns non-zero when it finds unmet or mismatched deps. Treat that as a real signal (the tree is broken) or swallow the exit code if you only want the listing.
npm ls some-pkg || true # print the tree without failing the job