Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does NPM handle version conflicts?

Since NPM version 3 node modules and dependencies are all installed at the same root level. But what if I install two modules that depend on two different versions of the same module? For instance, if I install async npm i [email protected], which requires lodash version 4.14.0, then I install yeoman npm i [email protected], which requires lodash version version 3.2.0, how does npm resolve this conflict?

like image 305
jwerre Avatar asked Feb 09 '17 21:02

jwerre


People also ask

Can npm manage multiple code versions?

Due to https://github.com/npm/npm/issues/2943, npm will never support the ability to alias packages and install multiple versions of the same package.

Does the npm version matter?

Either version ( npm@6 or npm@7 ) should work just fine. You just need to pick one with your coworker to avoid the package-lock. json churn (or not care about the lockfile churn).

How use npm specific version?

For npm install specific version, use npm install [package-name]@[version-number]. Use npm view [package-name] version to know the specific latest version of a package available on the npm registry. Use npm list [package-name] to know the specific latest version of an installed package.


1 Answers

All the dependencies and the internal dependencies tries to get a place in the root of the node_modules unless there is a conflict with the same dependency, but different version. When a conflict raises, it creates a sub node_modules under each dependency needed and pushes conflicting internal libraries in it.

EXAMPLE: Here, "A" internally depends on "[email protected]" and "B" depends on "[email protected]". When you execute install A and B like below:

npm install A npm install B  node_modules |_ A |_ alpha @v1.0 |_ B |    |_ node_modules |        |_ alpha @v2.0 |_ ... 

NOTE: Another node_modules created under "B" inside the main node_module.

For more details: visit this post.

like image 198
ShreeJ Avatar answered Sep 30 '22 01:09

ShreeJ