requires a peer but none was installed

Viewed 9301

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?

2 Answers

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
Related