【Vue报错】npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree npm ERR! npm ERR!

报错代码如下:

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: webvue@0.1.0
npm ERR! Found: vue@3.2.47
npm ERR! node_modules/vue
npm ERR!   vue@"^3.2.13" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer vue@"^2.5.17" from element-ui@2.15.12
npm ERR! node_modules/element-ui
npm ERR!   element-ui@"*" 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! See D:SoftWareLocationnode_jsnode_cacheeresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     D:SoftWareLocationnode_jsnode_cache_logs2023-02-09T11_40_48_239Z-debug-0.log

报错原因:由于npm版本太高导致此错误发。npm的版本只要超大于或等于7.x.x,会在某些方面上更加严格,就会导致出现这种情况,低于7.x.x不会出现这种情况

查看npm版本:npm -v

解决方案
1.在指令后面都添加上 --legacy-peer-deps,如下

npm xxx --legacy-peer-deps

2.在指令后面都加上 --force,如下

npm xxx --force

3.降低npm版本(不推荐,谨慎)

npm install npm@6.14.12 -g  //降低版本指令,版本自己可选择

因为降低版本后,容易导致npm和node不相容,会出现很大的问题!!!