Philippe Gioseffi
Philippe Gioseffi

Reputation: 1658

How does npm manage transitive modules?

If I have an A module in my application which uses a C module in version 1 and a B module that also uses this C module but in version 2, which version of C module my project will actually be using?

Something like below:

My project
|--- A module
     |--- C module version 1
|--- B module
     |--- C module version 2

Upvotes: 0

Views: 247

Answers (2)

El.
El.

Reputation: 1245

When you run npm install npm looks for package.json dependencies and peers recursively and install them all in their own folders. and if two dependencies have same dependency with different semantic version you would have both of versions but in different folders. For example in a project you might have about 20 thousand dependencies and all of them are installed by npm on node_module folder and that's why the folder is soooo big.

Upvotes: 2

Trần Đức Huy
Trần Đức Huy

Reputation: 104

No. You no need to care about sub node_module inside A module or B module. What you should care is how to use module A and B. Unless you want to use module C in side your code, u must install it independently. For example:

npm install C

In this case all module A, B and C are folders which same level.

node_module/
---Module A
     |---Module C (1)
---Module B
     |---Module C (2)
---Module C (*)

Summary: module C (*) is different with Module C (1) and (2). Maybe same version or different version.

Upvotes: 1

Related Questions