7

My package.json looks like this

{
  "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"
  }
}

When I run npm i it runs successfully but I got some warnings.

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.

I added these lines to package.json

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

But when I run npm i again I still get this warning

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.

with additional warning for the main application.
Why is that and how to get rid from this warning?

lapots
  • 12,553
  • 32
  • 121
  • 242
  • Possible duplicate of [What's the difference between dependencies, devDependencies and peerDependencies in npm package.json file?](https://stackoverflow.com/questions/18875674/whats-the-difference-between-dependencies-devdependencies-and-peerdependencies) – E_net4 Jun 30 '17 at 08:35
  • In short: you just add them in your project as normal dependencies. – E_net4 Jun 30 '17 at 08:36
  • you mean add them to `dependencies` with corresponding versions? Switching to `zone.js^0.7.2` lead to `ERR` and `unmet peer dependency zone.js@0.7.8` – lapots Jun 30 '17 at 08:44
  • The asked peer is for version 0.7.8, not ^0.7.2. – E_net4 Jun 30 '17 at 08:48
  • In my post they required `^0.7.2` - requires a peer of zone.js@^0.7.2 but none was installed - but when I added it started requiring `0.7.8` – lapots Jun 30 '17 at 08:53
  • Can you post the latest package.json to your question? – E_net4 Jun 30 '17 at 10:30
  • @E_net4 I decided not to fix this warn as it seems when I change angular version I will have another set of warnings – lapots Jun 30 '17 at 12:23
  • Possible duplicate of [npm WARN … requires a peer of … but none is installed. You must install peer dependencies yourself](https://stackoverflow.com/questions/46053414/npm-warn-requires-a-peer-of-but-none-is-installed-you-must-install-peer) – Peter Lamberg May 02 '19 at 06:13
  • [This answer has good explanation and candidates for solution on the possible duplicate question](https://stackoverflow.com/a/49188160/1148030) – Peter Lamberg May 02 '19 at 06:16
  • [Check out this answer with good explanation of the error message and possible solutions](https://stackoverflow.com/a/49188160/1148030) – Peter Lamberg May 02 '19 at 06:17

2 Answers2

2

TL;DR

Peer Dependencies are a special kind of dependencies - they used by packages which do not call them directly, giving the user (you) the control. Hence, you have to install these packages manually.

You do not need to add peerDependencies to your package.json.

The reason you're seeing these error is, some of your dependencies declare rxjs@5.0.0-rc.4 and zone.js@^0.7.2 in their package.json as peerDependencies. This is why when you've added peerDependencies in your package.json, you get these warning twice.

To understand more about Peer Dependencies I suggest reading these:

  1. Peer Dependencies
  2. What are those PeerDependencies in a NodeJS project?
  3. This great answer
yuval.bl
  • 4,890
  • 3
  • 17
  • 31
0

I delete the node_modules folder and run npm install. The error would go away.

Gundam Meister
  • 1,425
  • 2
  • 19
  • 29