node.js 如何修复 npm UNMET PEER DEPENDENCY 警告?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35738346/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I fix the npm UNMET PEER DEPENDENCY warning?
提问by Reza
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 mdierrors with:
我使用的是 Windows 10,使用 Node 5.6.0 和 npm 3.6.0。我正在尝试将 angular-material 和 mdi 安装到我的工作文件夹中。npm install angular-material mdi错误:
+-- [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?
如何解决此问题以安装 AngularJS Material 和 MDI?
采纳答案by Datsik
npm no longer installs peer dependencies so you need to install them manually, just do an npm installon the needed deps, and then try to install the main one again.
npm 不再安装对等依赖项,因此您需要手动安装它们,只需npm install对所需的 deps执行一次,然后再次尝试安装主要的依赖项。
Reply to comment:
回复评论:
it's right in that message, it says which deps you're missing
就在那个消息中,它说你错过了哪个 deps
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
所以你需要 npm install angular angular-animate angular-aria angular-material angular-messages mdi
回答by JayKrish
UNMET PEER DEPENDENCYerror is thrown when the dependencies of one or more modules specified in the package.jsonfile is not met.
Check the warnings carefully and update the package.jsonfile with correct versions of dependencies.
UNMET PEER DEPENDENCY当package.json文件中指定的一个或多个模块的依赖关系不满足时,会抛出错误。仔细检查警告并package.json使用正确版本的依赖项更新文件。
Then run
然后运行
rm -rf node_modules/
npm cache clean
npm install
This will install all the required dependencies correctly.
这将正确安装所有必需的依赖项。
回答by Anuj Sharma
In my case all the dependencies were already there. Please update NPMin that case as it might have been crashed. It solved my problem.
就我而言,所有依赖项都已经存在。在这种情况下,请更新NPM,因为它可能已崩溃。它解决了我的问题。
npm install -g npm
回答by alexoviedo999
回答by Thomas Mwania
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.
此错误的最可能原因之一可能是您在 package.json 中定义了旧版本。要解决此问题,请更改 package.json 中的版本以匹配 npm 抱怨的那些。
Once done, run npm install and voila!!.
完成后,运行 npm install 并瞧!!
回答by ohkts11
This answer doesn't apply all cases, but if you can't solve the error by simply typing npm install, this steps might help.
此答案并不适用于所有情况,但如果您无法通过简单地键入 来解决错误npm install,则此步骤可能会有所帮助。
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 ^)
这意味着您安装了 packageA 的 4.2.0 版本,但 [email protected] 需要 pakageA 的 3.xx 版本。( ^的解释)
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.
所以你可以通过将 packageA 降级到 3.xx 来解决这个错误,但通常你不想降级包。
好消息是,在某些情况下,packageB 只是跟不上 packageA,而 packageB 的维护者正在努力将 packageA 的对等依赖项提高到 4.xx
在这种情况下,您可以检查是否存在更高版本的 packageB需要 npm 或 github 中 packageA 的 4.2.0 版本。
For example, Go to release page
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.
如果在发布页面上找不到任何内容,请转到问题页面并按关键字搜索问题,例如peer. 您可能会找到有用的信息。
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.
1) 升级到你想要的版本
2) 暂时保留错误,等待稳定版本发布。
If you choose option1:
In many cases, the version does not have latesttagthus not stable. So you have to check what has changed in this update and make sure anything won`t break.
如果选择option1:
很多情况下,版本没有latest标签,因此不稳定。因此,您必须检查此更新中发生的更改,并确保任何内容都不会中断。
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.
如果您选择选项2:
如果pakageA 从版本3 升级到4 是微不足道的,或者如果pakageB 的维护者还没有测试pakageA 的版本4 但说应该没有问题,您可以考虑留下错误。
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.
最后,如果你想知道为什么你必须手动做这样的事情,这个链接解释得很好。
回答by user230910
Ok so i struggled for a long time trying to figure this out. Here is the nuclearoption, for when you have exhausted all other ways..
好的,所以我挣扎了很长时间试图弄清楚这一点。这是核选项,因为当你用尽所有其他方式时..
- Make a new folder on your pc.
- Download a brand new installation of angular - I used this guide: https://coursetro.com/posts/code/55/How-to-Install-an-Angular-4-App
- Run it, make sure it works
- Then install your dependancies one by one from your package.json file
- Run it after each one is installed
- 在你的电脑上新建一个文件夹。
- 下载全新安装的 angular - 我使用了本指南:https: //coursetro.com/posts/code/55/How-to-Install-an-Angular-4-App
- 运行它,确保它有效
- 然后从你的 package.json 文件中一一安装你的依赖
- 每一个安装好后运行
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.
完成后,它仍然有效,将您的实际代码导入到这个新项目中。修复较新版本的 angular 导致的任何编译错误。
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..
这就是为我所做的.. 1 小时的返工 vs 6 小时的试图找出 wtf 是错误的.. 希望我以这种方式开始..
回答by Samuel Thompson
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:
给定的答案并不总是有效。如果它不能解决您的问题。确保您还在package.json. 这对于解决这个头痛非常重要。例如:
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?
所以我的打字稿需要在 2.4.2 和 2.6 之间,对吗?
So I changed my typescript library from using "typescript": "^2.7"to using "typescript": "^2.5". Seems correct?
所以我将我的打字稿库从 using 更改"typescript": "^2.7"为 using "typescript": "^2.5"。似乎正确?
Wrong.
错误的。
The ^means that you are okay with npm using "typescript": "2.5"or "2.6"or "2.7"etc...
这^意味着您对 npm 使用"typescript": "2.5"or"2.6"或"2.7"等没问题...
If you want to learn what the ^and ~it mean see: What's the difference between tilde(~) and caret(^) in package.json?
如果您想了解 the^和~它的含义,请参阅: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.
您还必须确保该包存在。也许没有"typescript": "2.5.9"查找包号。为了真正安全~,^如果您不想阅读它们的意思,只需删除或。
回答by ktretyak
Today available Angular 2 rc.7, and I had a similar problem with [email protected]UNMET PEER DEPENDENCY.
今天可用的Angular 2 rc.7,我有一个与[email protected]UNMET PEER DEPENDENCY类似的问题。
If you, like me, simply replaced @angular/...rc.6to @angular/...rc.7- it's not enough. Because, for example, @angular/routerhas no rc.6version.
如果你像我一样,只是简单地替换@angular/...rc.6为@angular/...rc.7- 这还不够。因为,例如,@angular/router没有rc.6版本。
In this case, better review package.jsonin Quick start
在这种情况下,最好在快速入门中查看package.json
回答by Srinivas Jatoth
you can resolve by installing the UNMET dependencies globally.
您可以通过全局安装 UNMET 依赖项来解决。
example : npm install -g @angular/[email protected]
示例: npm install -g @angular/[email protected]
install each one by one. its worked for me.
一一安装。它对我有用。

