由于依赖性错误,无法将 Angular 从 10 更新到 11

Muh*_*raz 8 npm-install npm-update angular-upgrade angular angular10

我正在关注此网站并尝试通过以下命令将我的项目更新到 11.0。

npx @angular/cli@11 update @angular/core@11 @angular/cli@11
Run Code Online (Sandbox Code Playgroud)

每次我运行它时,都会出现以下错误:

npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: my-first-app@0.0.0
npm ERR! Found: @angular-devkit/build-angular@0.1002.4
npm ERR! node_modules/@angular-devkit/build-angular
npm ERR!   dev @angular-devkit/build-angular@"~0.1102.17" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! dev @angular-devkit/build-angular@"~0.1102.17" from the root project
npm ERR! Conflicting peer dependency: @angular/compiler-cli@11.2.14
npm ERR! node_modules/@angular/compiler-cli
npm ERR!   peer @angular/compiler-cli@"^11.0.0 || ^11.2.0-next" from @angular-devkit/build-angular@0.1102.17
npm ERR!   node_modules/@angular-devkit/build-angular
npm ERR!     dev @angular-devkit/build-angular@"~0.1102.17" from the root project
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!
Run Code Online (Sandbox Code Playgroud)

在其他类似的问题上,我发现这个命令被引用了很多

npm install --legacy-peer-deps
Run Code Online (Sandbox Code Playgroud)

我不确定上面的命令有什么帮助,因为我已经运行了npm install并且现在只是尝试使用npx @angular/cli@11 update @angular/core@11 @angular/cli@11

环境详情:

Global Angular CLI: 13.1.2
Local Angular CLI: 10.2.4
Angular version: 10.2.5
Node: 16.13.1
Run Code Online (Sandbox Code Playgroud)

我可以做哪些不同的事情来使其发挥作用?

Ekr*_*maz 10

我可以这样解决:

运行以下升级命令后

npx @角/cli@11 更新@角/核心@11 @角/cli@11

它因相同的错误而失败,但它更改了package.json角度包的文件。因此,在不更改 package.json 的情况下运行以下命令:

npm i --legacy-peer-deps

--legacy-peer-deps这里很重要。然后再次运行升级命令,它应该可以工作:

npx @角/cli@11 更新@角/核心@11 @角/cli@11

  • 为我工作,但我必须在第二个 ng 更新中添加 `--allow-dirty` (4认同)

小智 -2

1-访问Nodejs网站并将您的版本更新到最新的 LTS 版本。

2- 转到操作系统命令行并运行npm i -g npm以将 npm 更新到最新版本。

npm uninstall3-不断将您的全局 Angular 版本更新到 v11.0 npm install

4-如果这些都不起作用,请尝试在另一台计算机上更新。