NPM 安装期间的依赖问题
Dependency Issue During NPM Install
我在理解如何为 react
确定满足其对等(react-native
和 react-redux
)依赖关系的有效版本时遇到问题。这是我的 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.1
、15.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
文件比较陌生,希望这是一个简单的解决方案,但我尝试过的一切都是空的。
可能值得尝试重新安装这些依赖项,并希望为所有内容安装的当前版本都匹配。
换句话说,从 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 与您的进行比较。
react-native@0.35.0 需要 react 版本 15.3.x,它与 react 15.4.
不兼容
将依赖项中的 "react": "^15.3.2"
更改为 "react": "~15.3.2"
并重新执行 npm install
应该可以解决您的问题。
我在理解如何为 react
确定满足其对等(react-native
和 react-redux
)依赖关系的有效版本时遇到问题。这是我的 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.1
、15.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
文件比较陌生,希望这是一个简单的解决方案,但我尝试过的一切都是空的。
可能值得尝试重新安装这些依赖项,并希望为所有内容安装的当前版本都匹配。
换句话说,从 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 与您的进行比较。
react-native@0.35.0 需要 react 版本 15.3.x,它与 react 15.4.
不兼容将依赖项中的 "react": "^15.3.2"
更改为 "react": "~15.3.2"
并重新执行 npm install
应该可以解决您的问题。