Would like to understand, how npm handles installation of duplicate packages with same version.
- Does it ignore, if the same package - same version installed already?
- Does it install/overwrite again the same package?
For eg:
- Package A is dependent on package B and package C.
- Where Packages B and C are dependent on common package D version 1.0
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?
1 Answer 1
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]