'How to install npm peer dependencies automatically?
For example, when I install Angular2:
npm install --save angular2
[email protected] /Users/doug/Projects/dougludlow/temp
├── [email protected]
├── UNMET PEER DEPENDENCY es6-promise@^3.0.2
├── UNMET PEER DEPENDENCY es6-shim@^0.33.3
├── UNMET PEER DEPENDENCY [email protected]
├── UNMET PEER DEPENDENCY [email protected]
└── UNMET PEER DEPENDENCY [email protected]
npm WARN [email protected] requires a peer of es6-promise@^3.0.2 but none was installed.
npm WARN [email protected] requires a peer of es6-shim@^0.33.3 but none was installed.
npm WARN [email protected] requires a peer of [email protected] but none was installed.
npm WARN [email protected] requires a peer of [email protected] but none was installed.
npm WARN [email protected] requires a peer of [email protected] but none was installed.
Is there a magic flag that I can pass to npm that will install the peer dependencies as well? I haven't been able to find one... It's tedious to manually copy and paste the peer dependencies and make sure I have the correct versions.
In other words, I'd rather not have to do:
npm install --save [email protected] es6-promise@^3.0.2 es6-shim@^0.33.3 [email protected] [email protected] [email protected]
What is the better way?
Solution 1:[1]
I solved it by rewriting package.json with the exact values warnings were about.
Warnings when running npm:
npm WARN [email protected] requires a peer of es6-shim@^0.33.3 but none was installed.
npm WARN [email protected] requires a peer of [email protected]
In package.json, write
"es6-shim": "^0.33.3",
"reflect-metadata": "0.1.2",
Then, delete node_modules directory.
Finally, run the command below:
npm install
Solution 2:[2]
Cheat code helpful in this scenario and some others...
??? UNMET PEER DEPENDENCY @angular/[email protected]
??? UNMET PEER DEPENDENCY @angular/[email protected]
??? UNMET PEER DEPENDENCY @angular/[email protected]
??? UNMET PEER DEPENDENCY @angular/[email protected]
??? UNMET PEER DEPENDENCY @angular/[email protected]
??? UNMET PEER DEPENDENCY @angular/[email protected]
??? UNMET PEER DEPENDENCY @angular/[email protected]
??? UNMET PEER DEPENDENCY @angular/[email protected] >
- copy & paste your error into your code editor.
- Highlight an unwanted part with your curser. In this case
??? UNMET PEER DEPENDENCY - Press command + d a bunch of times.
- Press delete twice. (Press space if you accidentally highlighted
??? UNMET PEER DEPENDENCY) - Press up once. Add
npm install - Press down once. Add
--save - Copy your stuff back into the cli and run
npm install @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] --save
Solution 3:[3]
I experienced these errors when I was developing an npm package that had peerDependencies. I had to ensure that any peerDependencies were also listed as devDependencies. The project would not automatically use the globally installed packages.
Solution 4:[4]
The project npm-install-peers will detect peers and install them.
As of v1.0.1 it doesn't support writing back to the package.json automatically, which would essentially solve our need here.
Please add your support to issue in flight: https://github.com/spatie/npm-install-peers/issues/4
Solution 5:[5]
I was facing the same issue, lucky I found an alternative way to install peer dependencies along with the install command.
Step 1: $ npm i npm-install-peers -D
for more clarity about the plugin: https://www.npmjs.com/package/npm-install-peers
Step 2: Update package.json for magical script
....
"scripts": {
...
"postinstall": "npm-install-peers"
},
....
Step 3: Just need to hit the install command to get installed all plugins
$ npm install
Solution 6:[6]
Might be a little outdated but you can run npx install-peerdeps --yarn --dev PACKAGE_NAME.
Pass the --yarn flag if you wanna use yarn and --dev flag if you want the package and its peer deps to be added as dev dependencies.
Hope this helps
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | viruskinghjx |
| Solution 2 | wowkin2 |
| Solution 3 | joshweir |
| Solution 4 | bb216b3acfd8f72cbc8f899d4d6963 |
| Solution 5 | Vinesh Goyal |
| Solution 6 | Roy kathurima |
