角度更新 10.2 到 11

Posted

技术标签:

【中文标题】角度更新 10.2 到 11【英文标题】:Angular Update 10.2 to 11 【发布时间】:2021-02-25 09:28:57 【问题描述】:

我正在尝试将项目中的 Angular 从版本 10.2 更新到 11.0。 运行 ng 更新:

  @angular-devkit/build-angular      0.1002.0 -> 0.1100.1     ng update @angular-devkit/build-angular
  @angular/cdk                       10.2.7 -> 11.0.0         ng update @angular/cdk
  @angular/cli                       10.2.0 -> 11.0.1         ng update @angular/cli
  @angular/core                      10.2.3 -> 11.0.0         ng update @angular/core
  @angular/material                  10.2.7 -> 11.0.0         ng update @angular/material

不幸的是,我尝试更新的每个软件包都失败了。我尝试了 --force 和 --allowDirty 标志。

@angular-cli

npm ERR! Found: @angular-devkit/build-angular@0.1002.0
npm ERR! node_modules/@angular-devkit/build-angular
npm ERR!   dev @angular-devkit/build-angular@"~0.1100.1" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! dev @angular-devkit/build-angular@"~0.1100.1" from the root project
npm ERR! 
npm ERR! Conflicting peer dependency: @angular/compiler-cli@11.0.0
npm ERR! node_modules/@angular/compiler-cli
npm ERR!   peer @angular/compiler-cli@"^11.0.0 || ^11.0.0-next" from @angular-devkit/build- 
angular@0.1100.1
npm ERR!   node_modules/@angular-devkit/build-angular
npm ERR!     dev @angular-devkit/build-angular@"~0.1100.1" from the root project

@angular-devkit/build-angular

npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! Found: @angular-devkit/build-angular@0.1002.0
npm ERR! node_modules/@angular-devkit/build-angular
npm ERR!   dev @angular-devkit/build-angular@"~0.1100.1" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! dev @angular-devkit/build-angular@"~0.1100.1" from the root project
npm ERR! 
npm ERR! Conflicting peer dependency: @angular/compiler-cli@11.0.0
npm ERR! node_modules/@angular/compiler-cli
npm ERR!   peer @angular/compiler-cli@"^11.0.0 || ^11.0.0-next" from @angular-devkit/build-angular@0.1100.1
npm ERR!   node_modules/@angular-devkit/build-angular
npm ERR!     dev @angular-devkit/build-angular@"~0.1100.1" from the root project

@角度/材质

Installing packages (npm)...npm ERR! code ERESOLVE
npm ERR! Cannot read property 'length' of undefined

@angular/cdk

Found: @angular-devkit/build-angular@0.1002.0
npm ERR! node_modules/@angular-devkit/build-angular
npm ERR!   dev @angular-devkit/build-angular@"~0.1100.1" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! dev @angular-devkit/build-angular@"~0.1100.1" from the root project
npm ERR! 
npm ERR! Conflicting peer dependency: @angular/compiler-cli@11.0.0
npm ERR! node_modules/@angular/compiler-cli
npm ERR!   peer @angular/compiler-cli@"^11.0.0 || ^11.0.0-next" from @angular-devkit/build- 
angular@0.1100.1
npm ERR!   node_modules/@angular-devkit/build-angular
npm ERR!     dev @angular-devkit/build-angular@"~0.1100.1" from the root project

更新 按特定顺序安装后,我设法更新了,但现在 NPM 不会安装并给出此消息:

Found: @angular-devkit/build-angular@0.1002.0
npm ERR! node_modules/@angular-devkit/build-angular
npm ERR!   dev @angular-devkit/build-angular@"~0.1100.1" from the root 
project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! dev @angular-devkit/build-angular@"~0.1100.1" from the root 
project
npm ERR! 
npm ERR! Conflicting peer dependency: @angular/compiler-cli@11.0.0
npm ERR! node_modules/@angular/compiler-cli
npm ERR!   peer @angular/compiler-cli@"^11.0.0 || ^11.0.0-next" from 
@angular-devkit/build-angular@0.1100.1
npm ERR!   node_modules/@angular-devkit/build-angular
npm ERR!     dev @angular-devkit/build-angular@"~0.1100.1" from the 
root project

【问题讨论】:

【参考方案1】:

就我而言

删除 node_modules 和 package-lock.json npm 缓存清理 --force npm i --force

我认为问题是在节点升级到 v14 之后

【讨论】:

【参考方案2】:

我也遇到了同样的问题,删除node_modules,package-lock.json,运行npm install,现在一切正常!

【讨论】:

【参考方案3】:

遇到了同样的问题。对我来说,问题是代码编辑器是打开的,

关闭编辑器并运行ng update @angular/core @angular/cli angular 成功更新

【讨论】:

【参考方案4】:

我遇到了完全相同的问题,尝试了不同的升级命令,多次删除了 node_modules 文件夹,但仍然没有运气。 对我来说,问题在于我使用的是 Node v15。我卸载了它并重新安装了 Node v14 -> 工作

【讨论】:

可以确认。 (1) 降级到 Node 14。 (2) npm install,所以你必须更正 package.lock。 (3) 现在运行 Angular 从 10 升级到 11 并且它可以工作。 (4) 切换回节点 15。【参考方案5】:

我有同样的问题,我最终使用了纱线包管理器,它解决了这个问题。

【讨论】:

以上是关于角度更新 10.2 到 11的主要内容,如果未能解决你的问题,请参考以下文章

如何在 xavier agx 上更新到 cuda 10.2? [关闭]

无法将角度更新到版本 6

更新到角度6后找不到app-root

为啥我不能将第 11 个角度更新为第 12 个?

如何使用角度更新下拉列表的值?

如何从 Oracle 11g XE 导出“数据库”并将其导入 Oracle 10.2?