npm - 如何阅读 npm“冲突对等依赖”错误消息?
问题描述
我正在尝试升级我拥有的项目的一些 npm 依赖项,并且出现“冲突的对等依赖项”错误。
我在这个网站上看到很多问题,要求帮助修复此类错误。但是,我一直在努力寻找有关这些错误实际含义的信息。我觉得如果我理解了这一点,我就有很大的机会自己想办法解决这个问题。
这是我试图解释的错误消息:
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! Found: @angular-devkit/build-angular@0.1102.5
npm ERR! node_modules/@angular-devkit/build-angular
npm ERR! dev @angular-devkit/build-angular@"~0.1102.9" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! dev @angular-devkit/build-angular@"~0.1102.9" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: @angular/localize@11.2.10
npm ERR! node_modules/@angular/localize
npm ERR! peerOptional @angular/localize@"^11.0.0 || ^11.2.0-next" from @angular-devkit/build-angular@0.1102.9
npm ERR! node_modules/@angular-devkit/build-angular
npm ERR! dev @angular-devkit/build-angular@"~0.1102.9" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
这可以通过在这个 Github 分支npm install
的根目录中运行来重现(我使用的是 npm 。)7.10.0
我对“冲突对等依赖”错误的一般理解是,我依赖的某些包表达了对包版本规范的对等依赖,该包版本规范与我实际安装的包的版本不匹配。
例如,如果我的项目直接依赖于 packagesA
和B
,并且我有安装的版本12.0.0
,A
但我的版本对packageB
有对等依赖,那么我将收到冲突的对等依赖错误,因为我使用的是它可能与之不兼容。^11.0.0
A
B
A
Therefore, my best guess as to what this error message could mean is that some package I depend upon has a peer dependency on @angular/localize
version spec ^11.0.0 || ^11.2.0-next
, but this spec does not match the version of @angular/localize
I have installed.
When I look at my package-lock.json, I do see that the node_modules/@angular-devkit/build-angular
entry has an entry "@angular/localize": "^11.0.0 || ^11.2.0-next"
in its peerDependencies
.
However, this is the only mention of @angular/localize
anywhere in this file -- or indeed in package.json. I haven't explicitly requested for it to be installed. Furthermore, it is marked as "optional": true
in the peerDependenciesMeta
of node_modules/@angular-devkit/build-angular
. So it's surprising to see an error message related to it.
The error mentions that the specific conflicting peer dependency is @angular/localize@11.2.10
. I don't see where that version number is coming from. But regardless, it actually seems to match the dependency specification underneath: if I go to semver.npmjs.com and type in @angular/localize
as the package and ^11.0.0 || ^11.2.0-next
as the version range, I see version 11.2.10
of the package highlighted in green, indicating that it matches the range.
So I'd really appreciate some help understanding in detail what this error message is telling me. I don't know why npm
is trying to install 11.2.10
of @angular/localize
, or why it thinks this conflicts with the peer dependency specification of @angular-devkit/build-angular
. It feels like I might be misunderstanding this message completely.
I'm guessing this boils down to some kind of incompatibility between the latest published versions of some of the Angular packages. If anyone has any pointers on how this particular error should be fixed, that would be great -- but I'm much more interested in simply understanding what the error message is telling me, so I can work it out for myself.
Many thanks in advance!
解决方案
Reading through this GitHub issue, it appears my interpretation of the error message was correct, and that this is in fact a bug in npm
.
This appears to have been reported as npm/cli/issues/3083; a fix has been merged, so I guess we just have to wait until it gets included in some upcoming npm
release.
推荐阅读
- c# - 返回 ContentResult 列表对象的单元测试控制器
- java - 为什么我在处理 3 中的素数分解代码使用这么多内存,我怎样才能让它使用更少的内存?
- c# - 如何通过主视图模型将 UserControl 内容更改为另一个 UserControl。如何在内容之间导航
- javascript - javascript (PWA) 是否可以检测假 gps / 模拟 gps?
- excel - 使用用户窗体命令按钮时,在 VBA 中将文本从工作表传递到工作表不起作用
- android - 即使升级到 1.2.0-alpha01,Android TextInputLayout 前缀/后缀文本也不会出现
- spring - 如何在应用程序运行时以编程方式更改 Spring Boot 的配置属性
- reactjs - 反应引导
- php - PHP 中 PM 到 AM 的时差
- react-native - React Native 渲染方法中的 For 循环