如何解决 Angular 更新问题对等依赖冲突:@angular/[email protected]

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

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

这是输出:

PS C:\Projects\frontend> npx ng update @angular/cli@13
The installed Angular CLI version is outdated.
Installing a temporary Angular CLI versioned 13.3.9 to perform the update.
✔ Package successfully installed.
Using package manager: 'npm'
Collecting installed dependencies...
Found 46 dependencies.
Fetching dependency metadata from registry...
    Updating package.json with dependency @angular-devkit/build-angular @ "13.3.9" (was "12.2.18")...
    Updating package.json with dependency @angular/cli @ "13.3.9" (was "12.2.18")...
    Updating package.json with dependency @angular/compiler-cli @ "13.3.11" (was "12.2.16")...
    Updating package.json with dependency typescript @ "4.6.4" (was "4.3.5")...
    Updating package.json with dependency @angular/animations @ "13.3.11" (was "12.2.16")...
    Updating package.json with dependency @angular/common @ "13.3.11" (was "12.2.16")...
    Updating package.json with dependency @angular/compiler @ "13.3.11" (was "12.2.16")...
    Updating package.json with dependency @angular/core @ "13.3.11" (was "12.2.16")...
    Updating package.json with dependency @angular/forms @ "13.3.11" (was "12.2.16")...
    Updating package.json with dependency @angular/platform-browser @ "13.3.11" (was "12.2.16")...
    Updating package.json with dependency @angular/platform-browser-dynamic @ "13.3.11" (was "12.2.16")...
    Updating package.json with dependency @angular/router @ "13.3.11" (was "12.2.16")...
  UPDATE package.json (2773 bytes)
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: @angular-devkit/[email protected]
npm ERR! node_modules/@angular-devkit/build-angular
npm ERR!   dev @angular-devkit/build-angular@"~13.3.9" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! dev @angular-devkit/build-angular@"~13.3.9" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: @angular/[email protected]
npm ERR! node_modules/@angular/compiler-cli
npm ERR!   peer @angular/compiler-cli@"^13.0.0 || ^13.3.0-rc.0" from @angular-devkit/[email protected]
npm ERR!   node_modules/@angular-devkit/build-angular
npm ERR!     dev @angular-devkit/build-angular@"~13.3.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.

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

node.js angular npm
4个回答
9
投票

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

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

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


9
投票

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

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

1
投票

Angular 更新指南中,建议使用下面的 ngx update 命令进行更新:

npx @angular/cli@13 update @angular/core@13 @angular/cli@13

我得到了冲突的对等依赖错误:

    npm ERR! Conflicting peer dependency: @angular/[email protected]
    npm ERR! node_modules/@angular/compiler-cli
    npm ERR!   peer @angular/compiler-cli@"^13.0.0 || ^13.3.0-rc.0" from @angular-devkit/[email protected]
    npm ERR!   node_modules/@angular-devkit/build-angular
    npm ERR!     dev @angular-devkit/build-angular@"~13.3.10" from the root project 

我将 ngx 命令更改为特定的角度版本,然后它运行成功:

npx @angular/[email protected] update @angular/[email protected] @angular/[email protected]

0
投票

我的问题与

package.lock.json
有关。我刚刚删除了它,重新安装软件包后,生成了一个新的
package.lock.json

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