如何解决 Angular 更新问题冲突的对等依赖:@angular/compiler-cli@13.3.11

ctw*_*twx 11 node.js npm angular

我尝试使用官方升级指南将当前的 Angular 12 应用程序更新到 13,但失败了。我不确定问题是什么,坦率地说,我不认为 npm 错误消息是不言自明的。

\n

这是输出:

\n
PS C:\\Projects\\frontend> npx ng update @angular/cli@13\nThe installed Angular CLI version is outdated.\nInstalling a temporary Angular CLI versioned 13.3.9 to perform the update.\n\xe2\x9c\x94 Package successfully installed.\nUsing package manager: 'npm'\nCollecting installed dependencies...\nFound 46 dependencies.\nFetching dependency metadata from registry...\n    Updating package.json with dependency @angular-devkit/build-angular @ "13.3.9" (was "12.2.18")...\n    Updating package.json with dependency @angular/cli @ "13.3.9" (was "12.2.18")...\n    Updating package.json with dependency @angular/compiler-cli @ "13.3.11" (was "12.2.16")...\n    Updating package.json with dependency typescript @ "4.6.4" (was "4.3.5")...\n    Updating package.json with dependency @angular/animations @ "13.3.11" (was "12.2.16")...\n    Updating package.json with dependency @angular/common @ "13.3.11" (was "12.2.16")...\n    Updating package.json with dependency @angular/compiler @ "13.3.11" (was "12.2.16")...\n    Updating package.json with dependency @angular/core @ "13.3.11" (was "12.2.16")...\n    Updating package.json with dependency @angular/forms @ "13.3.11" (was "12.2.16")...\n    Updating package.json with dependency @angular/platform-browser @ "13.3.11" (was "12.2.16")...\n    Updating package.json with dependency @angular/platform-browser-dynamic @ "13.3.11" (was "12.2.16")...\n    Updating package.json with dependency @angular/router @ "13.3.11" (was "12.2.16")...\n  UPDATE package.json (2773 bytes)\nnpm ERR! code ERESOLVE\nnpm ERR! ERESOLVE could not resolve\nnpm ERR!\nnpm ERR! While resolving: frontend@0.0.0\nnpm ERR! Found: @angular-devkit/build-angular@12.2.18\nnpm ERR! node_modules/@angular-devkit/build-angular\nnpm ERR!   dev @angular-devkit/build-angular@"~13.3.9" from the root project\nnpm ERR!\nnpm ERR! Could not resolve dependency:\nnpm ERR! dev @angular-devkit/build-angular@"~13.3.9" from the root project\nnpm ERR!\nnpm ERR! Conflicting peer dependency: @angular/compiler-cli@13.3.11\nnpm ERR! node_modules/@angular/compiler-cli\nnpm ERR!   peer @angular/compiler-cli@"^13.0.0 || ^13.3.0-rc.0" from @angular-devkit/build-angular@13.3.9\nnpm ERR!   node_modules/@angular-devkit/build-angular\nnpm ERR!     dev @angular-devkit/build-angular@"~13.3.9" from the root project\nnpm ERR!\nnpm ERR! Fix the upstream dependency conflict, or retry\nnpm ERR! this command with --force, or --legacy-peer-deps\nnpm ERR! to accept an incorrect (and potentially broken) dependency resolution.\n
Run Code Online (Sandbox Code Playgroud)\n

有人可以告诉我问题是什么以及如何升级吗?

\n

小智 9

出现此错误是因为您拥有节点 16.X 或更高版本。npm 比以前更严格了。

解决方案1:降级您的节点版本

解决方案 2:通过将 build-angle 升级到 13.3.9 来修复这些错误

  • 比 --force 对我有用的一个稍微干净的选项是在 `.npmrc` 中添加 `legacy-peer-deps=true`,然后重试。不过,可能想在升级后删除它。青年MMV (6认同)

小智 8

正如 @lyngvi 的评论中所建议的,这对我有用:

  1. 在项目根目录中创建文件 .npmrc
  2. 添加legacy-peer-deps=true
  3. 将 .npmrc 提交到 git (或其他 scm,如果有)
  4. 执行角度升级
  5. (可选)删除 .npmrc