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?
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.
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).
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.
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.
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