前端项目中有时候出现对等依赖(peer dependencies)报错,通常是因为npm或yarn在安装某个依赖包时,发现你的项目直接或间接依赖的某些包需要特定版本的其他包作为其依赖,但这些依赖并未明确列在项目的`package.json`文件中,或者与项目中已有的依赖版本不兼容。
While resolving:
...Conflicting peer dependency: vue@3.3.4
node_modules/vue
peer vue@">= 2.5 < 2.7"...
from the root project
Fix the upstream dependency conflict, or retry
this command with --force or --legacy-peer-deps
to accept an incorrect (and potentially broken) dependency resolution.
解决方案
在安装命令后面加上–force 或者–legacy-peer-deps,让它忽略这个冲突
npm i xxxxxxx@2.0 --legacy-peer-deps
这样安装有个问题,在之后安装其他包的时候还是需要加上这个后缀,所以可以先在package.json文件中将要安装的依赖加上,然后删除node-modules和package-lock.json文件,重新npm install