sof
sof

Reputation: 9649

How to find reverse dependencies on npm package?

I'd like to find out which packages depend on express among the installed sails/kraken/loopback/hapi/koa etc. Are there npm sub-commands or other ways to locally list all reverse dependencies on one specific npm package?

Upvotes: 202

Views: 99334

Answers (4)

Reuben
Reuben

Reputation: 163

npm explain since v7

This command will print the chain of dependencies causing a given package to be installed in the current project.


For a PowerShell version of @Neil Gaetano Lindberg's answer:

Get-ChildItem -Path .\node_modules\ -Filter package.json -Recurse | Select-String -Pattern "<the_package_name>"

Upvotes: 1

peterhil
peterhil

Reputation: 1566

In case someone is using pnpm, this should help to find packages that depend on lodash for example:

pnpm list --depth 1 | grep --color -E '(^\w|\slodash)'

Upvotes: 5

Neil Gaetano Lindberg
Neil Gaetano Lindberg

Reputation: 2935

I specifically wanted to find what package used a dependency that was breaking an initial install. This may help somebody out trying todo the same:

find ./node_modules/ -name package.json | xargs grep <the_package_name>

Upvotes: 80

hassansin
hassansin

Reputation: 17498

Adding package name after npm ls will show you tree only with the specified package.

npm ls express

Upvotes: 318

Related Questions