Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find why an indirect dependency is installed

Tags:

node.js

npm

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 ?

like image 511
Jazz Avatar asked Sep 13 '25 05:09

Jazz


1 Answers

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
└─┬ [email protected]
  └── [email protected]
like image 170
peteb Avatar answered Sep 15 '25 23:09

peteb