Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find the dependency that brought another dependency in Node.js

Now that npm installs dependencies in a flat structure the node_modules dir is crowded with lots and lots of dependencies and I have a hard time tracing why a particular dependency is there.

For example, when installing one of my dependencies, I get a warning that cross-spawn-asyc is deprecated and cross-spawn should be used instead. But having a closer look I see that my dependency is actually using cross-spawn but apparently something deeper in its dependency hierarchy still uses the old cross-spawn-async library.

How can I find that dependency which causes this problem rather than going through package.json of 100+ directories under node_modules?

like image 814
AlexStack Avatar asked Aug 14 '16 09:08

AlexStack


2 Answers

You can use npm ls:

npm ls cross-spawn-asya

This will show all the dependency trees that include the given package. This could look similar to (with the example of minimatch):

+-- [email protected]
| `-- [email protected]
|   `-- [email protected]
|     `-- [email protected] 
+-- [email protected]
| `-- [email protected]
|   `-- [email protected] 
+-- [email protected]
| `-- [email protected] 
+-- [email protected]
| `-- [email protected]
|   +-- [email protected]
|   | `-- [email protected]
|   |   `-- [email protected] 
|   `-- [email protected] 
like image 178
str Avatar answered Oct 14 '22 19:10

str


I think that this npm command may help:

npm ls <package_name>

It will show you the structure of dependencies to your package as tree. The package you are looking for will be shown in different color or highlighted in another way, so it will be easy to find it.

like image 23
Slawomir Pasko Avatar answered Oct 14 '22 19:10

Slawomir Pasko