The original problem is: A depends on B v1.0, C depends on B v2.0, then B will have A conflict.

npm v2

NPM V2 uses a nested approach to resolve conflicts, as shown in the following figure. It raises new questions:B saves multiple copies of wasted space.

npm v3

NPM V3 uses flat mode to extract the same modules as possible to the root directory, as shown below.

Flat mode is not perfect, and there are two problems:

  1. There will still be redundant space, put B v1.0 to the root directory, B v2.0 will still be nested, and vice versa
  2. The Phantom dependency problem

Shadow dependency problem

For shadow dependencies, the glob dependencies are not declared in package.json, but they are used in the code. Glob is actually a dependency of Rimraf, promoted to the root by flat Mode.

Json {"name": "my-library", "version": "1.0.0", "main": "lib/index.js", "dependencies": {" minimatch ":" ^ 3.0.4 "}, "devDependencies" : {" rimraf ": Var width = require("brace expansion"); "^2.6.2"} var width = require("brace expansion"); / /??? var glob = require("glob") // ???Copy the code

In addition to being difficult to maintain, it can cause other problems. For example, devDependencies will be installed for local development, but will not be installed for release, so that there will be no globs at the time of release and it will not work properly.

PNPM: Perfect solution

In the structure of PNMP directory, the method of nesting avoids the problem of shadow dependence, and the method of soft link solves the problem of module reuse.