npm Community Forum (Archive)

The npm community forum has been discontinued.

To discuss usage of npm, visit the GitHub Support Community.

Different versions of the same module specified in different child dependencies are not installing correctly

I have a project that has 2 modules A and B, In module A, there is a module C with version 1.0.0 in the “dependency” of its package.json. In module B, there is module C with version 2.0.0 in the “dependency” of its package.json. The structure looks like below

-
 - A
  - C@1.0.0
 - B
  - C@2.0.0

I run npm install . C@1.0.0 is installed in the node_modules folder under module A, C@2.0.0 is installed under the root node_modules folder. Here is the folder structure

node_modules
 - A
  - node_modules
   - C@1.0.0
 - B
 - C@2.0.0

I have 2 questions:

  1. Why C@2.0.0 is not installed under B?
  2. Module A is not using C@1.0.0 which is installed in its own node_modules folder, instead, both module A and B use C@2.0.0 which is in the top level. How can I make it so that module A uses C@1.0.0 and module B uses C@2.0.0?

npm that I tested are 5.5.1, 6.9.2, 6.10.1