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

问题原因:在 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 忽略对应的警告提示:.npmrc 配置文件中添加 strict-peer-dependencies=false ,这意味着将关闭严格的对等依赖模式。操作命令如下:参考链接:
欢迎访问:天问博客