【问题标题】:How do you properly resolve NPM dependencies in projects that require conflicting versions?在需要冲突版本的项目中,如何正确解决 NPM 依赖关系?
【发布时间】:2021-04-10 22:33:11
【问题描述】:

我正在尝试使用指令herereact-native-navigation 构建游乐场应用程序。一个简单的npm install 失败,因为对等依赖项有react: "*"react-native: "*",所以今天(2021 年1 月)NPM 尝试安装react@17.0.1,但也尝试安装react-native@0.63.4,这需要react@16.13.1。我收到以下错误:

npm ERR! While resolving: react-native-navigation@7.7.0
npm ERR! Found: react@17.0.1
npm ERR! node_modules/react
npm ERR!   peer react@"*" from the root project
...
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"16.13.1" from react-native@0.63.4
npm ERR! node_modules/react-native
npm ERR!   peer react-native@"*" from the root project
npm ERR!   peer react-native@">=0.59" from @react-native-community/datetimepicker@2.6.2
npm ERR!   node_modules/@react-native-community/datetimepicker
npm ERR!

然后我尝试通过在我的根项目中安装 react@16.13.1 来解决这个问题,希望 NPM 能够检测到该版本并将其用作对等依赖项,但后来发现 @react-native-community/datetimepicker@2.6.2 依赖于 react-native-windows@^0.6.20,这取决于react@16.11.0,给我这个错误:

npm ERR! Found: react@16.13.1
npm ERR! node_modules/react
npm ERR!   dev react@"16.13.1" from the root project
...
npm ERR! Could not resolve dependency:
npm ERR! peer react@"16.11.0" from react-native-windows@0.62.20
npm ERR! node_modules/@react-native-community/datetimepicker/node_modules/react-native-windows
npm ERR!   optional react-native-windows@"^0.62.0-0" from @react-native-community/datetimepicker@2.6.2
npm ERR!   node_modules/@react-native-community/datetimepicker
npm ERR!     dev @react-native-community/datetimepicker@"^2.5.0" from the root project
npm ERR!     1 more (react-native-ui-lib)
npm ERR!

我该如何深入了解这一点?我期待一切都能与npm install 一起工作。安装项目的正确方法是什么,或者在启动项目之前必须不断调试依赖冲突是否很常见?

【问题讨论】:

  • 我试过了,没有报错。

标签: node.js reactjs react-native npm react-native-navigation


【解决方案1】:

事实证明,我使用的节点 15.0.x 显然太新了。降级到 14.15.1 有效。

【讨论】:

  • 选择一个可以解决问题的答案,即使 OP 回答了他自己的问题。
【解决方案2】:

我也在使用节点 15.0.x。降级到 14.x.x 有效。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-02-02
    • 2013-06-04
    • 1970-01-01
    • 1970-01-01
    • 2018-11-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-18
    相关资源
    最近更新 更多