pnpm install出现:ERR_PNPM_PEER_DEP_ISSUES Unmet peer dependencies

使用 pnpm install 安装项目依赖时出现:ERR_PNPM_PEER_DEP_ISSUES Unmet peer dependencies,在 pnpm github issues 中找到相关解决方案。

pnpm && npm

一、前言

  1. 完整日志
ERR_PNPM_PEER_DEP_ISSUES Unmet peer dependencies

.
└─┬ koa-views
  └─┬ consolidate
    └── ✕ unmet peer react@^16.13.1: found 18.1.0

hint: If you don't want pnpm to fail on peer dependency issues, set the "strict-peer-dependencies" setting to "false".
  1. 问题原因:在 npm 3 中,不会再强制安装 peerDependencies (对等依赖)中所指定的包,而是通过警告的方式来提示我们。pnpm 会在全局缓存已经下载过的依赖包,如果全局缓存的依赖版本与项目 package.json 中指定的版本不一致,就会出现这种 hint 警告。

  2. pnpm 团队成员给出的解答:

There are two types of peer deps: optional peer dependencies and non-optional ones. The warnings are only printed for non-optional peer dependencies. If a package works without the peer dependencies, then it should be declared as optional peer dependency. Optional peer dependencies are supported by npm/yarn/pnpm for a long time.

二、处理方案

  1. 在项目的 package.json 中配置 peerDependencyRules 忽略对应的警告提示:
{
  "pnpm": {
    "peerDependencyRules": {
      "ignoreMissing": [
        "react"
      ]
    }
  }
}
  1. .npmrc 配置文件中添加 strict-peer-dependencies=false ,这意味着将关闭严格的对等依赖模式。操作命令如下:
npm config set strict-peer-dependencies=false

参考链接:

  • https://github.com/pnpm/pnpm/issues/4684

欢迎访问:天问博客

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值