npm installation software: ERESOLVE unable to resolve dependency tree

Solution to npm version error report

When installing project dependencies, it is very likely that the installation will not be successful. There is a big reason for this, which may be caused by your npm version.

1.npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree

2.ERESOLVE unable to resolve dependency tree

The error message is as follows:

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/webpack
npm ERR!   dev webpack@"^4.43.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer webpack@">=5" from [email protected]
npm ERR! node_modules/babel-loader
npm ERR!   dev babel-loader@"*" from the root project
npm ERR!
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!
npm ERR! For a full report see:

1. The reason for the error

In newer versions of npm, by default npm install will fail when encountering conflicting peerDependencies.

2. Solutions

Use --force or --legacy-peer-deps to resolve this situation.

 --force 会无视冲突,并强制获取远端npm库资源,当有资源冲突时覆盖掉原先的版本。

--legacy-peer-deps标志是在v7中引入的,目的是绕过peerDependency自动安装;
它告诉 npm忽略项目中引入的各个modules之间的相同modules但不同版本的问题并继续安装,
保证各个引入的依赖之间对自身所使用的不同版本modules共存。

It is recommended to use --legacy-peer-depsa safer

Type in terminal

npm install --legacy-peer-deps
 npm install --save-dev @babel/core @babel/preset-env @babel/preset-react babel-loader 
 --legacy-peer-deps

Guess you like

Origin blog.csdn.net/weixin_43883625/article/details/129889892