How does NPM handle version conflicts?

Solution 1:

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.