【问题标题】:requires a peer but none was installed需要一个对等点,但没有安装
【发布时间】:2017-12-04 03:44:12
【问题描述】:

我的package.json 看起来像这样

{
  "name": "hello-world",
  "version": "1.0.0",
  "description": "The Hello World",
  "author": "",
  "license": "MIT",
  "scripts": {
    "start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\" ",
    "lite": "lite-server",
    "postinstall": "typings install",
    "tsc": "tsc",
    "tsc:w": "tsc -w",
    "typings": "typings"
  },
  "dependencies": {
    "@angular/common": "~2.0.1",
    "@angular/compiler": "~2.0.1",
    "@angular/core": "~2.0.1",
    "@angular/http": "~2.0.1",
    "@angular/platform-browser": "~2.0.1",
    "@angular/platform-browser-dynamic": "~2.0.1",
    "@angular/router": "~3.0.1",
    "@angular/upgrade": "~2.0.1",

    "systemjs": "0.19.39",
    "core-js": "^2.4.1",
    "reflect-metadata": "^0.1.8",
    "rxjs": "5.0.0-beta.12",
    "zone.js": "^0.6.25",

    "angular-in-memory-web-api": "~0.1.1",
    "bootstrap": "4.0.0-alpha.4"
  },
  "devDependencies": {
    "concurrently": "^3.0.0",
    "lite-server": "^2.2.2",
    "typescript": "^2.0.3",
    "typings": "^1.4.0"
  }
}

当我运行 npm i 时,它运行成功,但我收到了一些警告。

npm WARN angular-in-memory-web-api@0.1.17 requires a peer of rxjs@5.0.0-rc.4 but none was installed.
npm WARN angular-in-memory-web-api@0.1.17 requires a peer of zone.js@^0.7.2 but none was installed.

我将这些行添加到package.json

"peerDependencies": {
    "rxjs": "5.0.0-rc.4",
    "zone.js": "^0.7.2"
}

但是当我再次运行 npm i 时,我仍然收到此警告

npm WARN hello-world@1.0.0 requires a peer of rxjs@5.0.0-rc.4 but none was installed.
npm WARN hello-world@1.0.0 requires a peer of zone.js@^0.7.2 but none was installed.
npm WARN angular-in-memory-web-api@0.1.17 requires a peer of rxjs@5.0.0-rc.4 but none was installed.
npm WARN angular-in-memory-web-api@0.1.17 requires a peer of zone.js@^0.7.2 but none was installed.

对主应用程序附加警告。
为什么会这样以及如何消除此警告?

【问题讨论】:

  • 简而言之:您只需将它们作为正常依赖项添加到项目中即可。
  • 你的意思是把它们添加到dependencies 对应的版本?切换到zone.js^0.7.2 导致ERRunmet peer dependency zone.js@0.7.8
  • 请求的对等体是 0.7.8 版本,而不是 ^0.7.2。
  • 在我的帖子中,他们需要 ^0.7.2 - 需要 zone.js@^0.7.2 的对等但没有安装 - 但是当我添加它时,它开始需要 0.7.8

标签: npm package.json


【解决方案1】:

我删除node_modules 文件夹并运行npm install。错误会消失。

【讨论】:

    【解决方案2】:

    TL;DR

    Peer Dependencies 是一种特殊的依赖关系——它们被不直接调用它们的包使用,从而给予用户(您)控制权。因此,您必须手动安装这些软件包。

    您无需将peerDependencies 添加到您的package.json

    您看到这些错误的原因是,您的一些依赖项在其package.json 中将rxjs@5.0.0-rc.4zone.js@^0.7.2 声明为peerDependencies。这就是为什么当您在 package.json 中添加 peerDependencies 时,您会收到两次警告。

    要了解有关对等依赖项的更多信息,我建议阅读以下内容:

    1. Peer Dependencies
    2. What are those PeerDependencies in a NodeJS project?
    3. 这个great answer

    【讨论】:

      猜你喜欢
      • 2017-12-18
      • 2021-01-26
      • 1970-01-01
      • 2016-12-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-03
      • 2017-04-09
      相关资源
      最近更新 更多