'PeerDependencies with npm > v7

As explained in the npm documentation, after npm v7 migration, now PeerDependencies are installed by default. Here is the behavior from the documentation:

Trying to install another plugin with a conflicting requirement may cause an error if the tree cannot be resolved correctly.

When is a plugin considered as a conflicting requirement? What do they mean by the tree cannot be resolved correctly?

Therefore, I created different use cases to have a better understanding, tell me if I am correct.

Use case 1

Package.json of my project
{
  //...
  "dependencies": {
    "a": "1.0.0"
  }
}
Package.json of a
{
  //...
  "peerDependencies": {
    "b": "^2.0.0"
  }
}

Here is the result:

node_modules
  |--- a (v 1.0.0)
  |--- b (v 2.0.0)

Use case 2

Package.json of my project
{
  //...
  "dependencies": {
    "a": "1.0.0",
    "b": "2.5.0"
  }
}
Package.json of a
{
  //...
  "peerDependencies": {
    "b": "^2.0.0"
  }
}

Here is the result:

node_modules
  |--- a (v 1.0.0)
  |--- b (v 2.5.0)

Use case 3

Package.json of my project
{
  //...
  "dependencies": {
    "a": "1.0.0",
    "b": "3.2.0"
  }
}
Package.json of a
{
  //...
  "peerDependencies": {
    "b": "^2.0.0"
  }
}

Here is the result:

node_modules
  |--- a (v 1.0.0)
       |--- node_modules
              |--- b (v 2.0.0)
  |--- b (v 3.2.0)

Does the last use case work? In which use case, it can not resolve the tree?

npm


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source