【问题标题】:Npm peer dependency errorNpm 对等依赖错误
【发布时间】:2016-09-08 04:13:15
【问题描述】:

我使用 npm install 命令反复收到 npm peer 依赖错误。这是我的 package.json,我对 react 和 webpack 有未满足的对等依赖

    npm WARN react-datepicker@0.25.0 requires a peer of react@^0.14.0 but none was installed.
    npm WARN babel-loader@6.2.4 requires a peer of webpack@1 || ^2.1.0-beta but none was installed.
    npm WARN desktop-react@1.0.0 No repository field.
    npm WARN desktop-react@1.0.0 license should be a valid SPDX license expression

{
  "name": "xxxxxxxxx",
  "version": "x.x.x",
  "description": "",
  "main": "index.js",
  "author": "",
  "license": "xxxxxxx",
  "dependencies": {
    "bootstrap": "^3.3.6",
    "fs": "0.0.2",
    "history": "^1.17.0",
    "immutable": "^3.8.1",
    "isomorphic-fetch": "^2.2.1",
    "lodash": "^4.11.1",
    "moment": "^2.13.0",
    "react": "^15.0.1",
    "react-autosuggest": "^3.7.3",
    "react-bootstrap": "^0.29.1",
    "react-datepicker": "^0.25.0",
    "react-dom": "^15.0.1",
    "react-redux": "^4.4.5",
    "react-router": "^2.3.0",
    "react-select": "^1.0.0-beta12",
    "redux": "^3.5.2"
  },
  "devDependencies": {
    "babel-core": "^6.7.7",
    "babel-loader": "^6.2.4",
    "babel-preset-es2015": "^6.6.0",
    "babel-preset-react": "^6.5.0",
    "bootstrap": "^3.3.6",
    "css-loader": "^0.23.1",
    "redux-devtools": "^3.2.0",
    "style-loader": "^0.13.1"
  }
}

【问题讨论】:

标签: node.js npm package.json


【解决方案1】:

首先,这些不是错误,而是警告。它们实际上不会阻止您的代码运行,它们只是在您的依赖项出现问题时提醒您。

实际上,peerDependencies 是包指定的一种方式,“要使用我,您还应该安装 x 版本的 y 包”。在您的情况下,您有两个问题:

  • react-datepicker 的那个版本希望你使用 React 14,但你有 React 15。如果你将 react-datepicker 更新到最新版本,那个版本将与 v15 兼容——也就是说,很少有破坏如果我没记错的话,这两个版本的 React 之间会发生变化,所以如果你因为某种原因无法使用特定版本的日期选择器,应该忽略该警告是安全的。不过,您的里程可能会有所不同。
  • babel-loader 依赖于 Webpack,但您没有安装它的任何版本。这似乎是您的错误。运行 npm install webpack --save-dev 应该会消失。

希望您能够在这种情况下理解将来如何解释这些警告!

【讨论】:

    【解决方案2】:

    有警告,而不是错误,但仍然值得修复。

    • react-datepicker:您应该升级到最新版本 (0.27.0),它将 react@^15.0.0 声明为对等依赖项。
    • babel-loaderinstallation instructions 解释说,使用 npm@3 您需要在 package.json 中显式声明对等依赖项(如 webpack)(使用 npm i webpack --save-dev)。

    desktop-react 警告可以忽略。

    【讨论】:

      猜你喜欢
      • 2015-11-16
      • 2018-04-22
      • 1970-01-01
      • 2022-11-10
      • 2016-12-25
      • 1970-01-01
      • 2021-07-15
      • 2014-08-08
      • 1970-01-01
      相关资源
      最近更新 更多