How to add npm dependency as peer dependency

As for now, there is NO WAY, you can install dependencies as peer-dependencies. You have to install then and manually move them to peerDependencies object in package.json

OLD ANSWER


The automatic install of peer dependencies was removed with npm v3, this feature is aging added in npm v7.

So update your npm to version 7 or higher will solve most of the problems.

If You need to install dependency as a peer dependency.

To install peer dependency, you actually need to manually modify your package.json file.

For example, if you want to install angular’s core component library as a peer dependency,

  1. npm i @angular/core

This will add a property in the dependencies object.

"dependencies": {
    "@angular/core": "^7.0.0"
}
  1. Move the installed package name to peerDependencies key.
"peerDependencies": {
    "@angular/core": "^7.0.0"
}

Extra:
if you need two versions of the same package then you modify the packge.json file like this,

"peerDependencies": {
   "@angular/core": "^6.0.0"
   "@angular/core": "^7.0.0"
 }

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)