This is the fourth day of my participation in the August More text Challenge. For details, see:August is more challenging

NPM handles dependencies and dependency conflicts

In NPM (v2) and previous versions, NPM handles dependencies by recursively installing modules’ dependencies one by one to form a large dependency tree. This mechanism can resolve dependency bundle conflicts, but it can also cause the following problems:

1. The dependency level is too deep, and the deletion is slow.

2. Different modules will depend on the same package, which is redundant and may even cause bugs

Dependency sharing and conflict

In A project, it is possible for the project to depend on package A and package B, while package B depends on package A.

NPM V2 first determines whether package A is compatible. If it is compatible, it will only install package A in the project path. If it is not compatible, it will install another package A in package B

After NPM V3, NPM took a more rational approach to solving the previous dependency hell problem. NPM v3 tries to share dependencies and dependencies in the node_modules folder in the project root directory. If there is a conflict that cannot be placed in the tiled directory due to the inconsistent version requirements, the NPM V2 processing method falls back to NPM V2 and stores the conflicting modules in node_modules under the module.

Current projects are dependent module, for example, [email protected], [email protected], [email protected] is dependent on the module [email protected], [email protected], [email protected] [email protected] again depends on the module, [email protected]. Note that since the two versions of module C ([email protected] and [email protected]) are dependent on each other, since the modules are stored in the same node_modules directory, the two versions cannot be tiled in the same directory at the same time. Therefore, One version of C modules will be placed in the child node_modules directory as NPM V2 handles.

Existing problems

If package A registers objects under window, A conflict occurs

peerDependencies

When a dependent module X is defined in peerDependencies instead of devDependencies or Dependencies, projects that depend on that module do not automatically download the dependencies.