Jazz Jazz - 5 months ago 15
Node.js Question

Find why an indirect dependency is installed

I know that somewhere in my dependency tree I depend on a library, but I would like to find easily which libraries depends on it (a bit like

aptitude why
for Debian packages).

e.g. if my library depends on A that depends on B that depends on C, I would like to type the command
npm-why C
and it replies with the tree my-lib -> A -> B -> C

If I use
npm ls
I have a huge tree and it is very tedious to follow the tree of dependencies to go up to the root.

Is there a command that already do that ?

Answer

npm ls command will take a package as a parameter and display any packages that depend upon it along with its path.

npm ls <pkg>

Description

This command will print to stdout all the versions of packages that are installed, as well as their dependencies, in a tree-structure.

Positional arguments are name@version-range identifiers, which will limit the results to only the paths to the packages named. Note that nested packages will also show the paths to the specified packages. For example, running npm ls promzard in npm's source tree will show:

npm@@VERSION@ /path/to/npm
└─┬ init-package-json@0.0.4
  └── promzard@0.1.5
Comments