Failed to install dependencies (npm install)

Having trouble resolving the dependency tree (dependency conflicts)

npm i failed to install dependencies and reported the following error:

npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: [email protected]      
npm ERR! Found: [email protected]
npm ERR! node_modules/eslint
npm ERR!   dev eslint@"5.0.0" from the root project
npm ERR!   peer eslint@">= 1.6.0 < 7.0.0" from @vue/[email protected]
npm ERR!   node_modules/@vue/cli-plugin-eslint
npm ERR!     dev @vue/cli-plugin-eslint@"~4.5.0" from the root project
npm ERR!   9 more (eslint-loader, babel-eslint, eslint-config-standard, ...)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer eslint@">=1.6.0 <5.0.0" from [email protected]
npm ERR! node_modules/eslint-loader
npm ERR!   dev eslint-loader@"1.9.0" from the root project
npm ERR! 
npm ERR! Conflicting peer dependency: [email protected]
npm ERR! node_modules/eslint
npm ERR!   peer eslint@">=1.6.0 <5.0.0" from [email protected]
npm ERR!   node_modules/eslint-loader
npm ERR!     dev eslint-loader@"1.9.0" from the root project
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See C:\Users\Administrator\AppData\Local\npm-cache\eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Administrator\AppData\Local\npm-cache\_logs\2023-03-22T02_14_02_271Z-debug-0.log

solution

Execute npm install --legacy-peer-deps

In the package.json file, there is an object called peerDependencies (peer dependencies), which contains all the packages needed in the project or all packages with the same version number that the user is downloading, which means peer dependencies Specifies that our package is compatible with a specific version of an npm package. The best example of a peer-to-peer dependency is React, a JS library for declaratively creating user interfaces.

Starting from version v7 of npm, install is downloaded in the form of peerDependencies by default.

The strategy is as follows:

  1. If the user explicitly depends on the core library in the package.json file in the root directory, the peerDependencies declaration in each subproject can be ignored

  1. If the user does not explicitly depend on the core library, then install the dependencies into the project root directory according to the version declared in the peerDependencies of the subproject

If the version of the package that the user depends on is incompatible with the version of the package that each sub-project depends on, an error will be reported (problem that the dependency tree cannot be resolved (dependency conflict)) and the user will be asked to fix it by himself, which will cause the interruption of the installation process. (Because it was introduced from npm v7, this error will not occur in npm v3-v6)

The npm install --legacy-peer-deps command is used to bypass the automatic installation of dependencies in peerDependency; it tells npm to ignore the problem that the dependent modules introduced in the project have the same dependencies but different versions, and go in the way of npm v3-v6 Proceed with the installation operation.

So in fact, this command does not really resolve the conflict, but ignores the conflict and performs the download operation in an "outdated" (v3-v6) way.

reference link

https://blog.csdn.net/devcloud/article/details/124469666

Guess you like

Origin blog.csdn.net/qq_54029413/article/details/129704140