【问题标题】:Dependency Issue During NPM InstallNPM 安装期间的依赖问题
【发布时间】:2017-03-20 19:19:27
【问题描述】:

我在理解如何为满足其对等(react-nativereact-redux)依赖项的 react 的有效版本进行 sepcify 时遇到问题。这是我的package.json

...
"dependencies": {
  "react": "^15.3.2",
  "react-native": "0.35.0"
  "react-redux": "4.4.5",
  "redux": "3.6.0",
}

此项目的初始开发工作(约 2 个月前)在 npm install 期间没有任何问题,但将此 repo 克隆到新环境并运行 npm install 会产生以下问题:

npm WARN peerDependencies The peer dependency react@~15.3.1 included from react-native will no
npm WARN peerDependencies longer be automatically installed to fulfill the peerDependency 
npm WARN peerDependencies in npm 3+. Your application will need to depend on it explicitly.

npm ERR! node v4.4.7
npm ERR! npm  v2.15.8
npm ERR! code EPEERINVALID

npm ERR! peerinvalid The package react@15.4.2 does not satisfy its siblings' peerDependencies requirements!
npm ERR! peerinvalid Peer react-native@0.35.0 wants react@~15.3.1
npm ERR! peerinvalid Peer react-redux@4.4.5 wants react@^0.14.0 || ^15.0.0-0

似乎正在尝试安装 react@15.4.2,这是截至 2017 年 3 月 20 日的最新版本,据我了解 ^ semver 规范是正确的。

我尝试指定版本15.3.115.3.2^15.3.1^15.3.2~15.3.1 等,但无论我输入什么,问题仍然存在。

还查看了https://github.com/facebook/react-native/blob/0.35-stable/package.json上的文件:

"peerDependencies": {
  "react": "~15.3.1"
},

https://github.com/reactjs/react-redux/blob/4.x/package.json:

"peerDependencies": {
  "react": "^0.14.0 || ^15.0.0-0 || ^15.4.0-0",
  "redux": "^2.0.0 || ^3.0.0"
},

我对 package.json 这样的文件比较陌生,希望这是一个简单的解决方案,但我尝试过的一切都是空的。

【问题讨论】:

  • 哦,另外,也许考虑更新你的 node 和 npm 版本,这些都比较旧了。

标签: reactjs npm react-native react-redux npm-install


【解决方案1】:

react-native@0.35.0 需要一个 15.3.x 的 react 版本,它与 react 15.4 不兼容。

将您的依赖项中的 "react": "^15.3.2" 更改为 "react": "~15.3.2" 并执行新的 npm install 应该可以解决您的问题。

【讨论】:

  • 我会再次检查一下,就像我的问题一样:“我已经尝试指定版本 15.3.1、15.3.2、^15.3.1、^15.3.2、~15.3。 1, etc etc”(包括 15.3.2 我认为)
  • Welp,这似乎是我解决这个依赖问题所需要的。打开另一个问题 react-native-router-flux 需要 "react": "^15.4.2",但这解决了眼前的问题。
【解决方案2】:

可能值得尝试重新安装这些依赖项,并希望为所有内容安装的当前版本匹配。

换句话说,从你的 package.json 中删除这些行,使用 rm -rf node_modules 删除你的模块,然后转到 npm i --save react react-native redux react-redux

或者,检查 https://github.com/react-community/create-react-native-app 并创建一个新应用并将 package.json 与您的进行比较。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-03-14
    • 2020-09-29
    • 2017-12-23
    • 1970-01-01
    • 2018-02-01
    • 2015-04-07
    • 1970-01-01
    相关资源
    最近更新 更多