npm对等依赖报错(peer dependencies)原因以及如何解决

前端项目中有时候出现对等依赖(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

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值