How do I fix the npm UNMET PEER DEPENDENCY warning?
Asked Answered
R

17

307

I'm on Windows 10, with Node 5.6.0 and npm 3.6.0. I'm trying to install angular-material and mdi into my working folder. npm install angular-material mdi errors with:

+-- [email protected]

+-- UNMET PEER DEPENDENCY angular-animate@^1.5.0

+-- UNMET PEER DEPENDENCY angular-aria@^1.5.0

+-- [email protected]

+-- UNMET PEER DEPENDENCY angular-messages@^1.5.0 `-- [email protected]

npm WARN enoent ENOENT: no such file or directory, open
'C:\Users\xxxxx\Desktop\ngClassifieds\package.json' 

npm WARN [email protected] requires a peer of
angular-animate@^1.5.0 but none was installed. 

npm WARN [email protected] requires a peer of angular-aria@^1.5.0
but none was installed. 

npm WARN [email protected] requires a peer of
angular-messages@^1.5.0 but none was installed.

How do I resolve this to get AngularJS Material and MDI installed?

Revealment answered 2/3, 2016 at 4:9 Comment(4)
Does these type of error create any problem?Odelle
Not for Reza, so it's to late, but for any others... Try this: npm view angular-material peerDependenciesLeuctra
In general, you may not always want to resolve an unmet dependency. For example, it some-package has a dependency on other-package@^1.5.0, and you have [email protected] installed, you may not need to roll back the version. It would be better to test if you are actually having problems with the newer version.Spark
See also Why do peer dependencies exist?Georg
M
241

npm no longer installs peer dependencies so you need to install them manually, just do an npm install on the needed deps, and then try to install the main one again.


Reply to comment:

it's right in that message, it says which deps you're missing

UNMET PEER DEPENDENCY angular-animate@^1.5.0 +-- 
UNMET PEER DEPENDENCY angular-aria@^1.5.0 +-- [email protected] +
UNMET PEER DEPENDENCY angular-messages@^1.5.0 `-- [email protected]` 

So you need to npm install angular angular-animate angular-aria angular-material angular-messages mdi

Makalu answered 2/3, 2016 at 4:11 Comment(10)
is there a way to find the deps for angular-material so I can install?Revealment
@Revealment I'm putting this comment into my answer for formatting purposesMakalu
never mind, I answered my own question - i just did a 'npm install angular-animate' on so forthRevealment
Do you need to add these new dependencies to your package.json?Bronchia
@caffinatedmonkey that would be idealMakalu
@caffinatedmonkey if you specify the --save switch npm will update your package.json for you (or --save-dev if the package is a development dependency)Knoll
what is peer dependencyIngroup
There's currently a small bug in angular-material which will disallow installation against peers on version 1.6, even though the release is claimed as compatible with 1.6 versions of it's peers - if this is causing you issues, you can hack the angular-material/package.json peerDependencies to include <=1.6 instead of <1.6 until the release is cleaned up. github.com/angular/material/issues/10353Nafis
isnt the whole point of npm to have it manage all those dependencies for you? if I do an npm install, then get a list of a bunch of unmet dependencies that I have to manually add to my composer.json file by hand, what value am I even getting from npm at that point?Openandshut
From Npm v7.0.0, peer dependencies are again installed for youCurtilage
B
84

UNMET PEER DEPENDENCY error is thrown when the dependencies of one or more modules specified in the package.json file is not met. Check the warnings carefully and update the package.json file with correct versions of dependencies.

Then run

rm -rf node_modules/
npm cache clean
npm install

This will install all the required dependencies correctly.

Bluegreen answered 4/10, 2016 at 12:45 Comment(7)
what is peer dependencyIngroup
When you install a package it might in turn depend on specific versions of other packages. If you don't provide a correct dependent version of package then "Peer dependency" is un met. So you need to update the expected version of the dependant packages to solve that.Bluegreen
That didn't work for me. I still got a warning about a peer being required.Tapia
Much cleaner than the accepted solution! This one set of code handles every possible case of the op's problem, instead of the specific issue they have.Riannon
using the npm cache clean command gives the error: As of npm@5, the npm cache self-heals from corruption issues and data extracted from the cache is guaranteed to be valid. If you want to make sure everything is consistent, use 'npm cache verify' instead. npm ERR! If you're sure you want to delete the entire cache, rerun this command with --force.Oilskin
@AdamZerner maybe you need to do npm install --save <dependendant_peer_package> <peer_dependency_package> to explicitly resolve the unmet dependency.Chantry
A parameter cannot be found that matches parameter name 'rf'.Yuu
B
36

In my case all the dependencies were already there. Please update NPM in that case as it might have been crashed. It solved my problem.

npm install -g npm
Bartizan answered 21/6, 2017 at 0:2 Comment(4)
Worked for me. I was receiving the error UNMET PEER DEPENDENCY typescript when trying to install tslint. once updating the npm, had to install typscript first and then install tslint.Attenuation
For some reason, I had to run it more than once until it had all its own dependencies updated.Tattan
This broke npm for me and resulted in a bunch of errors.Monophthong
Unfortunately didn't work for me either. It gives ERR! Unsupported URL Type "npm:": npm:string-width@^4.2.0.Unruffled
W
22

EDIT 2020

From npm v7.0.0, npm automatically installs peer dependencies. It is one of the reasons to upgrade to v7.

https://github.blog/2020-10-13-presenting-v7-0-0-of-the-npm-cli/

Also this page explains the rationale of peer dependencies very well. https://github.com/npm/rfcs/blob/latest/implemented/0025-install-peer-deps.md


This answer doesn’t apply all cases, but if you can’t solve the error by simply typing npm install , this steps might help.

Let`s say you got this error.

UNMET PEER DEPENDENCY [email protected]

npm WARN [email protected] requires a peer of packageA@^3.1.0 but none was installed.

This means you installed version 4.2.0 of packageA, but [email protected] needs version 3.x.x of pakageA. (explanation of ^)

So you can resolve this error by downgrading packageA to 3.x.x, but usually you don`t want to downgrade the package.
Good news is that in some cases, packageB is just not keeping up with packageA and maintainer of packageB is trying hard to raise the peer dependency of packageA to 4.x.x.
In that case, you can check if there is a higher version of packageB that requires version 4.2.0 of packageA in the npm or github.

For example, Go to release pageenter image description here

Oftentimes you can find breaking change about dependency like this.

packageB v4.0.0-beta.0

BREAKING CHANGE
package: requires packageA >= v4.0.0

If you don’t find anything on release page, go to issue page and search issue by keyword like peer. You may find useful information.

enter image description here

At this point, you have two options.

  1. Upgrade to the version you want
  2. Leave error for the time being, wait until stable version is released.

If you choose option1:
In many cases, the version does not have latest tag thus not stable. So you have to check what has changed in this update and make sure anything won`t break.

If you choose option2:
If upgrade of pakageA from version 3 to 4 is trivial, or if maintainer of pakageB didn’t test version 4 of pakageA yet but says it should be no problem, you may consider leaving the error.

In both case, it is best to thoroughly test if it does not break anything.

Lastly, if you wanna know why you have to manually do such a thing, this link explains well.

Webfooted answered 26/11, 2018 at 14:20 Comment(0)
S
19

npm-install-peers worked for me.

npm install -g npm-install-peers
Semilunar answered 20/1, 2017 at 4:11 Comment(2)
Didn't work for me: "This package doesn't seem to have any peerDependencies". However, I have several messages like "npm ERR! peer dep missing: @angular/common@^5.0.0 || ^6.0.0, required by @agm/[email protected]"Assembled
This package only install direct peer deps of the current package and dies not handle the peer deps of the deps of the package (peers of children).Philippa
B
7

One of the most possible causes of this error could be that you have defined older version in your package.json. To solve this problem, change the versions in the package.json to match those npm is complaining about.

Once done, run npm install and voila!!.

Boreas answered 5/4, 2017 at 16:42 Comment(0)
M
6

The given answer wont always work. If it does not fix your issue. Make sure that you are also using the correct symbol in your package.json. This is very important to fix that headache. For example:

warning " > @angular/[email protected]" has incorrect peer dependency "typescript@>=2.4.2 <2.7".
warning " > [email protected]" has incorrect peer dependency "typescript@>=2.4.2 <2.6".

So my typescript needs to be between 2.4.2 and 2.6 right?

So I changed my typescript library from using "typescript": "^2.7" to using "typescript": "^2.5". Seems correct?

Wrong.

The ^ means that you are okay with npm using "typescript": "2.5" or "2.6" or "2.7" etc...

If you want to learn what the ^ and ~ it mean see: What's the difference between tilde(~) and caret(^) in package.json?

Also you have to make sure that the package exists. Maybe there is no "typescript": "2.5.9" look up the package numbers. To be really safe just remove the ~ or the ^ if you dont want to read what they mean.

Margarettemargarida answered 5/3, 2018 at 19:35 Comment(4)
Thank you for this explanation. What happens if I use two libraries where the first (e.g. library-one) uses e.g. a peer of package@<2.6 and the other (library-two) a peer of package@>2.7? Then will I end up to having to deal with two versions of package in my codebase? How will I know that when I use library-one I have to use it with [email protected] meanwhile when I use library-two I have to use it with [email protected]?Emanuel
@Emanuel try it out. import an old package and a new one that share a package. npm magically deals with it. It will get try and use the right version for both of them if it can, but it can also use both at the same time through npm magicMargarettemargarida
Do you mean that this feature of NPM works at the ES6 import level?Emanuel
what I meant is I don't really know how it works, but it is not hard to test so just test it and see what it does.Margarettemargarida
U
3

Ok so i struggled for a long time trying to figure this out. Here is the nuclear option, for when you have exhausted all other ways..

When you are done, and it still works, import your actual code into this new project. Fix any compile errors the newer version of angular causes.

Thats what did it for me.. 1 hour of rework vs 6 hours of trying to figure out wtf was wrong.. wish i did it this way to start..

Uttica answered 15/5, 2017 at 8:8 Comment(1)
OP is using AngularJSLunula
P
2

Today available Angular 2 rc.7, and I had a similar problem with [email protected] UNMET PEER DEPENDENCY.

If you, like me, simply replaced @angular/...rc.6 to @angular/...rc.7 - it's not enough. Because, for example, @angular/router has no rc.6 version.

In this case, better review package.json in Quick start

Prior answered 13/9, 2016 at 14:38 Comment(1)
OP is using AngularJSLunula
D
2

This issue can also occur when trying to fix a security vulnerability issue on a dependency.

Here is what I did: Audited installed dependencies

npm audit

If there are fix available, running the following would fix the issue most of the time:

npm audit fix

Some issues would have SEMVER WARNING, following the link would give us hint on how to do a manual review and/or what to do next.

Doing a bit more research led me to discovering this command:

npm upgrade

Seems npm audit fix did not account on updating peer dependencies, and running npm upgrade would fixed unmet peer dependencies. Now check if we resolved the issue by running:

npm list

This will give us all dependencies for our project and warn us of any unmet peer deps errors. Upgrading for the most part is actually better than staying on older version of the package you are using, if you are not having a security vulnerability issue npm install is also a viable option.

Dov answered 16/6, 2021 at 1:25 Comment(0)
V
1

You will get this warning if you are using npm v6 or before. After npm v7.0, npm development team has stated that they will automatically install peer dependencies, all together. Therefore, now you don't want to install your peer dependencies manually.

You can install npm v7.0 using this command,

npm install -g npm@7

Learn more about npm v7.0 from this blog post, published by the Github Blog.

Vinosity answered 11/11, 2020 at 16:50 Comment(0)
G
0

In case you wish to keep the current version of angular, you can visit this version compatibility checker to check which version of angular-material is best for your current angular version. You can also check peer dependencies of angular-material using angular-material compatibility.

Green answered 1/2, 2021 at 6:43 Comment(0)
B
0

I removed package-lock.json and node_module , switch over to YARN and this solved the issue

Blackfellow answered 1/8, 2022 at 15:41 Comment(0)
J
0

I was receiving the following error: warning " > [email protected]" has unmet peer dependency "[email protected]".

It looks like the main reason was that that I had the "react-native" package installed aside from the "npx react-native" that comes with the node install.

Once I removed the 'react-native' package, I was able to successfully use "npx react-native init packagename" syntax.

You can check the react-native documentation regarding the above issue on the react native site: https://reactnative.dev/docs/environment-setup

Jos answered 17/10, 2022 at 20:26 Comment(0)
S
0

If there is an error related to dependency like "could not resolve dependency" then follow these steps:- 1.)npm cache clean --force
npm i --force
2.) If above step didn't work then try to install lower node version and then use first step again .

Stepchild answered 9/3, 2023 at 9:11 Comment(0)
P
0

Ensure that you've closed all running instances of the command line before installing any new packages.

I had two command-line instances running in my project: one for the Prisma studio and another for Next.js. I forgot to shut down the second instance, which caused the error.

Prolific answered 10/10, 2023 at 17:28 Comment(0)
E
-11

you can resolve by installing the UNMET dependencies globally.

example : npm install -g @angular/[email protected]

install each one by one. its worked for me.

Eisler answered 29/3, 2018 at 7:10 Comment(2)
Is this really the best solution, thought? Installing globally to ignore the actual "problem" for project dependencies?Psychodrama
This will install dependencies globally on your machine. Your peers will not be able to account for this in a shared environment.Blinnie

© 2022 - 2024 — McMap. All rights reserved.