如何解决对等依赖错误:包 react@15.3.2 不满足其兄弟的 peerDependencies 要求

Posted

技术标签:

【中文标题】如何解决对等依赖错误:包 react@15.3.2 不满足其兄弟的 peerDependencies 要求【英文标题】:How do I resolve peer dependency error: The package react@15.3.2 does not satisfy its siblings' peerDependencies requirements 【发布时间】:2017-02-09 19:53:20 【问题描述】:

我在运行 npm install 时收到此错误。这似乎是因为我无法满足某些对等依赖,但我不确定我需要修复哪个对等依赖。

λ npm install

npm ERR! Windows_NT 10.0.14393
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install"
npm ERR! node v4.6.0
npm ERR! npm  v2.15.9
npm ERR! code EPEERINVALID

npm ERR! peerinvalid The package react@15.3.2 does not satisfy its siblings' peerDependencies requirements!
npm ERR! peerinvalid Peer belle@2.0.7 wants react@>=0.14.0 || ^15.0.0-rc
npm ERR! peerinvalid Peer material-ui@0.15.4 wants react@^15.0.0
npm ERR! peerinvalid Peer react-infinite@0.9.2 wants react@^15.0.0
npm ERR! peerinvalid Peer react-input-field@1.2.4 wants react@>=0.12.0
npm ERR! peerinvalid Peer react-router@0.13.6 wants react@0.13.x || 0.14.x || ^15.0.1
npm ERR! peerinvalid Peer react-tap-event-plugin@0.2.2 wants react@^0.14.0
npm ERR! peerinvalid Peer react-toolbox@1.2.1 wants react@~0.14 || ~15.3.0
npm ERR! peerinvalid Peer react-addons-css-transition-group@15.3.2 wants react@^15.3.2
npm ERR! peerinvalid Peer react-dom@15.3.2 wants react@^15.3.2

npm ERR! Please include the following file with any support request:
npm ERR!     C:\Users\Daljeet\Documents\hive\client\npm-debug.log

我还附上了 package.json 的副本

dependencies: 

  "dependencies": 
    "belle": "^2.0.7",
    "body-parser": "^1.6.5",
    "bootstrap": "^3.3.0",
    "compression": "^1.0.11",
    "config": "^1.21.0",
    "config-js": "^1.1.9",
    "connect-ensure-login": "^0.1.1",
    "cors": "^2.4.1",
    "dateformat": "^1.0.12",
    "dotenv": "^0.4.0",
    "errorhandler": "^1.1.1",
    "express": "^4.8.5",
    "express-jwt": "^0.3.1",
    "flux": "^2.0.1",
    "i": "^0.3.5",
    "immutability-helper": "^2.0.0",
    "jsonwebtoken": "^5.0.1",
    "jwt-decode": "^1.1.0",
    "keymirror": "^0.1.1",
    "lodash": "4.0.0",
    "log4js": "^0.6.38",
    "material-ui": "~0.15.4",
    "mongoose": "^4.3.4",
    "morgan": "^1.2.3",
    "normalize.css": "^4.2.0",
    "pg": "^4.5.5",
    "react": "15.3.2",
    "react-infinite": "^0.9.2",
    "react-input-field": "^1.2.4",
    "react-mixin": "^1.1.0",
    "react-router": "^0.13.2",
    "react-star-rating": "^1.4.2",
    "react-tap-event-plugin": "~0.2.2",
    "react-toolbox": "^1.2.1",
    "react-virtual-list": "^1.8.0",
    "reqwest": "2.0.5",
    "when": "^3.7.2"
  ,
  "devDependencies": 
    "babelify": "^6.1.0",
    "browser-sync": "^2.1.6",
    "browserify": "^8.0.3",
    "clean-css": "^3.1.9",
    "eslint": "^0.14.1",
    "nodemon": "^1.5.0",
    "rework": "^1.0.1",
    "rework-npm": "^1.0.0",
    "rework-npm-cli": "^0.1.1",
    "serve": "^1.4.0",
    "uglify-js": "^2.4.15",
    "watchify": "^2.1.1"
  

【问题讨论】:

我也有同样的问题。以更简洁的形式:有人告诉我 v15.3.2 不满足对等依赖 ^0.14.8 || ^15.0.1——这是错误的,它确实满足那个semver范围。 你能从你的第一个代码块中删除所有的 npm 警告吗?这些有点无关紧要:错误才是问题所在。 我认为这些警告可以帮助您深入了解如何处理错误。 当我更新 npm "npm install npm -g" 然后降级反应时它起作用了; "react": "15.3.0",清除缓存:npm cache clear,删除 node_modules,rm -rf node_modules,并重新安装,npm install 只需更新npm npm install npm -g即可解决问题。 【参考方案1】:

当我:


    更新了 npm "npm install npm -g" 降级反应; "react": "15.3.0" 已清除缓存:npm cache clear 删除了 node_modules,rm -rf node_modules, 重新安装了node_modules,npm install

【讨论】:

npm install npm -g 实际上是做什么的?从 npm 安装 npm 包?【参考方案2】:

对我来说npm install --legacy-peer-deps 工作。请在使用前阅读此标志。

【讨论】:

【参考方案3】:

只需将节点包管理器 (npm) 更新到最新版本。

npm install npm -g

【讨论】:

【参考方案4】:

我遇到了同样的问题,我使用了以下东西:

1. Update the react version: "react": ^16.2.0" in package.json file
2. Delete the node modules by rm -rf node_modules
3. Run npm install
4. npm update

这对我有用。

【讨论】:

以上是关于如何解决对等依赖错误:包 react@15.3.2 不满足其兄弟的 peerDependencies 要求的主要内容,如果未能解决你的问题,请参考以下文章

Monorepo 中的对等依赖关系

npm 错误!如何使用 vue@2.6.14 安装满足对等依赖的编译器-sfc?

如何修复对等依赖项安装问题

使用 Yarn 安装包时,“不正确的对等依赖”是啥意思?

全局安装具有对等依赖关系的 npm 包(package.json 中未提及)

冲突的对等依赖关系:webpack@4.46.0 npm ERR!节点模块/webpack