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

一、前言
-
完整日志
ERR_PNPM_PEER_DEP_ISSUES Unmet peer dependencies
.
└─┬ koa-views
└─┬ consolidate
└── ? unmet peer react@^16.13.1: found 18.1.0hint: If you don’t want pnpm to fail on peer dependency issues, set the “strict-peer-dependencies” setting to “false”.
-
问题原因:在 npm 3 中,不会再强制安装
peerDependencies(对等依赖)中所指定的包,而是通过警告的方式来提示我们。pnpm 会在全局缓存已经下载过的依赖包,如果全局缓存的依赖版本与项目package.json中指定的版本不一致,就会出现这种hint警告。 -
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.
二、处理方案
-
在项目的
package.json中配置peerDependencyRules忽略对应的警告提示:{
“pnpm”: {
“peerDependencyRules”: {
“ignoreMissing”: [
“react”
]
}
}
} -
在
.npmrc配置文件中添加strict-peer-dependencies=false,这意味着将关闭严格的对等依赖模式。操作命令如下:npm config set strict-peer-dependencies=false
参考链接:
- https://github.com/pnpm/pnpm/issues/4684
欢迎访问:天问博客

在使用pnpm安装项目依赖时遇到'ERR_PNPM_PEER_DEP_ISSUES'错误,即未满足的对等依赖问题。问题源于npm 3以后对等依赖不再强制安装,而是警告。解决方案包括在pnpm配置中忽略警告或在npm全局配置中关闭严格对等依赖模式。可以通过修改pnpm的配置文件或运行npm命令来解决此问题。
7228

被折叠的 条评论
为什么被折叠?



