Would like to understand, how npm handles installation of duplicate packages with same version.
For eg:
so while running npm install will it try to install package D twice or only once and will ignore second occurrence as its already present in node_modules?
The NPM install algorithm states dependencies will be added as close to the top as is possible without breaking any other modules.
In your case, package B and C both depend on [email protected]. Since there is no possible conflict between the two dependencies, package D will be installed once at the top level.
For a rough representation, here is the original dependency tree you have imagined.
+ package A
+-- B
-- [email protected]
+-- C
-- [email protected]
Package A installs dep B and dep C at the same top level. Since there are no other conflicting versions of dep D in the tree, dep D also gets added to the top level for both dep B and dep C to use.
+ package A
+-- B
+-- C
+-- [email protected]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With