如何知道使用哪个版本的 Angular/Common 来满足依赖关系?

问题描述 投票:0回答:1

当我将更改部署到主分支时,管道失败了。如果我是正确的,该错误表明项目中不同依赖项所需的 @angular/common 版本存在冲突。根项目需要 @angular/common@"^16.0.0",而 [email protected] 需要 @angular/common@"^17.0.4" 的对等依赖项。

这是在 npm install 期间失败的管道中的错误:

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: [email protected].
npm ERR! Found: @angular/[email protected]
npm ERR! node_modules/@angular/common
npm ERR!   @angular/common@"^16.0.0" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer @angular/common@"^17.0.4" from [email protected]
npm ERR! node_modules/ngrx-store-localstorage
npm ERR!   ngrx-store-localstorage@"^16.0.0" 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.
npm ERR! 
npm ERR! See /root/.npm/eresolve-report.txt for a full report.
angular dependencies pipeline
1个回答
0
投票

首先,您必须确保

npm install
在您的本地计算机上运行。通常,问题来自于您使用
^
来指定依赖项的版本,请参阅here有关语义版本控制的更多详细信息。在这种情况下,您对依赖项及其依赖项的确切版本没有太多控制权,有时,项目会中断。我建议删除
^
以手动控制确切版本,并不时运行
npm outdated
,以查看是否要继续更新。静默自动更新可能会给你带来惊喜,比如昨天还可以,但今天“无缘无故”停止工作了。

然后,您应该确保您的部署使用所有依赖项的相同版本。这就是文件

package-lock.json
存在的原因。请参阅此处了解更多说明。我建议将此文件提交到您的存储库并运行
npm ci
来安装依赖项,请参阅 here

类似的方法应该应用于

yarn
包管理器或其他。

© www.soinside.com 2019 - 2024. All rights reserved.