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?
Asked
Active
Viewed 7.9k times
3 Answers
285
Adding package name after npm ls
will show you tree only with the specified package.
npm ls express

hassansin
- 16,918
- 3
- 43
- 49
-
7Thanks. The command `npm view express dependencies` shows only direct dependencies, but i can't figure out how to view its complete dependencies tree. – sof Aug 10 '15 at 16:28
-
11only works if you have the module installed into a node_modules folder... doesn't do you any good if you're trying to resolve a dry run. – worc Oct 12 '18 at 22:02
-
2For dev dependencies, use `npm ls --dev express` – dinesh ygv Dec 10 '20 at 10:08
-
1For scoped packages (which begin with @), using only the scope `@date-io` fails with `EINVALIDTAGNAME` error. Instead use the complete package name like `npm ls @date-io/date-fns` – gowthz Jan 28 '22 at 03:04
75
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>

Neil Gaetano Lindberg
- 2,488
- 26
- 23
-
-
3wow, finally a nice solution! I'd also add that `find ./node_modules -name package.json | xargs grep -e 'PACKAGE_NAME": "'` helps get rid of other mentions of the PACKAGE_NAME and focuses on instances where it is used with a version number.. – maricn Oct 06 '21 at 17:02
-
1and also good to mention is that this method can be used recursively to find what first level dependency ends up importing the specified package.. – maricn Oct 06 '21 at 17:03
-
4
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)'

peterhil
- 1,536
- 1
- 11
- 18