需要相同peerDependency的多个版本

问题描述 投票:3回答:2

当我在当前的反应项目上运行npm i时,我收到以下有关反应peerDependency的警告:

npm WARN [email protected] requires a peer of react@^16.0.0-0 < 16.4.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of react@^15.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of react@^0.14.0 || ^15.0.0 but none is installed. You must install peer dependencies yourself.

在我的package.json中,我使用的是最新版本的react:

"react": "^16.7.0"

我是node和npm的新手。我想知道安装npm peerDependencies的好习惯是什么:

1.)如果已在package.json中指定了更新版本,则可以忽略较低版本的警告。

2.)根据https://lexi-lambda.github.io/blog/2016/08/24/understanding-the-npm-dependency-model/https://github.com/npm/npm/issues/6565

npm提供依赖隔离,peerDepencies需要手动安装,所以我应该安装所有3个版本的反应,但我担心会破坏import语句。

3.)如果以上两者都不是,我应该在package.json中使用哪个版本。附:我的package.json中有很多依赖项,也可能需要最新版本。

node.js reactjs npm
2个回答
5
投票

进一步考虑Danyal的答案,你可以升级formy-react并删除react-tap-event-plugin:

  1. 更新formy-对最新版本的反应:(编写本文时为1.1.5),此软件包的最新版本支持react ^ 16。
  2. react-tap-event-plugin支持反应版本至版本16.4。你有几个选择: 降级反应:降级至16.4将删除所有警告,但将限制您将来升级的能力 删除react-tap-event-plugin:根据文档https://www.npmjs.com/package/react-tap-event-plugin。由于对以后的浏览器进行了修复,实际上不推荐使用此模块。查看blog post获取信息。 fork react-tap-event-plugin:我自己不会这样做,但你可以分叉插件并使用更新的react peerDependency自行发布。

2
投票

对等依赖性意味着包适用于与特定版本的依赖项一起使用,如果超出指定版本,则无法按预期工作。

在你的情况下,[email protected]需要一个小于16.4.0的React版本,[email protected]需要任何版本的React 15和[email protected]相同。

您需要从React 16.7.0降级,但如果您使用16.7.0功能,则可能会破坏您的应用程序,或者您可以删除软件包并使用另一个软件包或从开始自己编写软件包的逻辑。

提示:在实际考虑使用项目包之前,请务必确保在npm网站上阅读包依赖项。

© www.soinside.com 2019 - 2024. All rights reserved.