Angular 更新从 8 到 13 对等依赖问题
Angular update from 8 to 13 peer dependency problem
我正在按照 angular 更新指南更新我的 angular 应用程序,但我遇到了对等依赖项错误。
首先,我从 angular 8 更新到 9,但仍然存在对等依赖性错误。所以我将此命令与 --force
参数一起使用:
cmd /C "set "NG_DISABLE_VERSION_CHECK=1" && npx @angular/cli@9 update @angular/cli@9 @angular/core@9" --force
而且有效!
然后从Angular 9到10,方法与
相同
npx @angular/cli@10 update @angular/core@10 @angular/cli@10 --force
而且它也有效。现在我想继续 Angular 11、12 和 13,但是当我使用此命令时:
npx @angular/cli@11 update @angular/core@11 @angular/cli@11 --force
我收到这个错误:
The installed Angular CLI version is outdated.
Installing a temporary Angular CLI versioned 11.2.18 to perform the update.
Installing packages for tooling via npm.
Installed packages for tooling via npm.
Using package manager: 'npm'
Collecting installed dependencies...
Found 61 dependencies.
Fetching dependency metadata from registry...
Package "@swimlane/ngx-charts" has an incompatible peer dependency to "@angular/animations" (requires "7.x || 8.x" (extended), would install "11.2.14").
Package "@ng-bootstrap/ng-bootstrap" has an incompatible peer dependency to "@angular/forms" (requires "^8.0.0" (extended), would install "11.2.14").
Package "@swimlane/ngx-charts" has an incompatible peer dependency to "@angular/platform-browser" (requires "7.x || 8.x" (extended), would install "11.2.14").
Package "@swimlane/ngx-charts" has an incompatible peer dependency to "@angular/platform-browser-dynamic" (requires "7.x || 8.x" (extended), would install "11.2.14").
Updating package.json with dependency @angular-devkit/build-angular @ "0.1102.18" (was "0.1002.4")...
Updating package.json with dependency @angular/cli @ "11.2.18" (was "10.2.4")...
Updating package.json with dependency @angular/compiler-cli @ "11.2.14" (was "10.2.5")...
Updating package.json with dependency @angular/language-service @ "11.2.14" (was "10.2.5")...
Updating package.json with dependency karma @ "6.3.11" (was "5.0.9")...
Updating package.json with dependency @angular/animations @ "11.2.14" (was "10.2.5")...
Updating package.json with dependency @angular/common @ "11.2.14" (was "10.2.5")...
Updating package.json with dependency @angular/compiler @ "11.2.14" (was "10.2.5")...
Updating package.json with dependency @angular/core @ "11.2.14" (was "10.2.5")...
Updating package.json with dependency @angular/forms @ "11.2.14" (was "10.2.5")...
Updating package.json with dependency @angular/platform-browser @ "11.2.14" (was "10.2.5")...
Updating package.json with dependency @angular/platform-browser-dynamic @ "11.2.14" (was "10.2.5")...
Updating package.json with dependency @angular/router @ "11.2.14" (was "10.2.5")...
UPDATE package.json (2808 bytes)
⠧ Installing packages (npm)...npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: stacked@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.18" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! dev @angular-devkit/build-angular@"~0.1102.18" from the root project
npm ERR!
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.18
npm ERR! node_modules/@angular-devkit/build-angular
npm ERR! dev @angular-devkit/build-angular@"~0.1102.18" 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 C:\Users\leino\AppData\Local\npm-cache\eresolve-report.txt for a full report.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\leino\AppData\Local\npm-cache_logs22-01-14T16_41_50_262Z-debug.log
✖ Package install failed, see above.
× Migration failed. See above for further details.
我知道使用 --force
参数是个坏主意,但更喜欢在 angular 更新后解决对等依赖关系,而不是在每个版本上解决。
拜托,有人知道吗?
从 8 级升级到 13 级!!这就是我要做的!
使用
卸载全局@angular/cli
sudo npm uninstall -g @angular/cli
使用
安装最新的angular cli 全球版本
sudo npm install -g @angular/cli
使用
检查安装的全球版本
sudo npm list -g depth0
创建新项目使用
sudo ng new yourProjectName
删除 node_modules
文件夹和 package-lock.json file
移动您的旧项目文件(不要覆盖 angular.json
或 package.json
文件,而是从您的旧项目中移动非 angular npm 包 package.json
到你的新项目 package.json
文件)
运行 sudo npm install
运行 ng serve
解决您的应用错误
祝你好运
我今天遇到了完全相同的问题。我就是这样修复它的:
npx @angular/cli@11 update @angular/core@11 @angular/cli@11 --force
# now getting the same errors as above
npm install @angular-devkit/build-angular@~0.1102.18 --force
git checkout -- .
npx @angular/cli@11 update @angular/core@11 @angular/cli@11 --force
现在转到 package.json
并删除包含 @angular-devkit/build-ng-packagr
.
的行
执行这行:
rm package-lock.json
rm -rf node_modules
npm install
完成!
也许从 package.json 加上 npm install
中删除该特定行就足够了,上面的其他命令在不必要的地方但我宁愿告诉你我所做的一切:)
顺便说一下,在我尝试所有这些之前,我也按照上面的评论之一降级到 npm v7,但我认为这没有必要或没有任何帮助。
我刚遇到这个问题,运行这个命令帮我解决了:
npm install @angular-devkit/build-angular@~0.1102.18 --force
找到了!
那是我的节点版本的问题。我正在使用 v16.9 并安装节点 v14.19 解决了我的问题。
我借此机会安装了 windows-nvm 以便能够管理许多节点版本。
- 卸载节点
- 安装windows-nvmhttps://github.com/coreybutler/nvm-windows
- 使用节点 v14.19
- 升级到 angular 11 !
从版本 10 到 11 的主要区别在于 Angular 的模块 @angular-devkit/build-angular 及其相关的依赖项已移至单个模块。
你会注意到@angular-devkit/build-angular@0.1002.4变成了@angular-devkit/build-angular@semantic-versioning-that-aligns-with-the-rest-of-the-other-angular-modules.
话虽如此,您需要对 angular.json 和其他配置文件进行一些更改。 最简单的事情(在 运行 npx 更新之后)是创建一些临时 hello-world 项目,然后比较所有配置文件
版本 11 到 12 似乎更直接。然后从版本 12 到 13,他们需要你拥有 NodeJs 版本 12.20.0 或更高版本。例如,您可能需要进行一些代码调整:如果您使用 Service Workers 之类的东西,因为某些方法已被弃用。
我正在按照 angular 更新指南更新我的 angular 应用程序,但我遇到了对等依赖项错误。
首先,我从 angular 8 更新到 9,但仍然存在对等依赖性错误。所以我将此命令与 --force
参数一起使用:
cmd /C "set "NG_DISABLE_VERSION_CHECK=1" && npx @angular/cli@9 update @angular/cli@9 @angular/core@9" --force
而且有效!
然后从Angular 9到10,方法与
相同npx @angular/cli@10 update @angular/core@10 @angular/cli@10 --force
而且它也有效。现在我想继续 Angular 11、12 和 13,但是当我使用此命令时:
npx @angular/cli@11 update @angular/core@11 @angular/cli@11 --force
我收到这个错误:
The installed Angular CLI version is outdated.
Installing a temporary Angular CLI versioned 11.2.18 to perform the update.
Installing packages for tooling via npm.
Installed packages for tooling via npm.
Using package manager: 'npm'
Collecting installed dependencies...
Found 61 dependencies.
Fetching dependency metadata from registry...
Package "@swimlane/ngx-charts" has an incompatible peer dependency to "@angular/animations" (requires "7.x || 8.x" (extended), would install "11.2.14").
Package "@ng-bootstrap/ng-bootstrap" has an incompatible peer dependency to "@angular/forms" (requires "^8.0.0" (extended), would install "11.2.14").
Package "@swimlane/ngx-charts" has an incompatible peer dependency to "@angular/platform-browser" (requires "7.x || 8.x" (extended), would install "11.2.14").
Package "@swimlane/ngx-charts" has an incompatible peer dependency to "@angular/platform-browser-dynamic" (requires "7.x || 8.x" (extended), would install "11.2.14").
Updating package.json with dependency @angular-devkit/build-angular @ "0.1102.18" (was "0.1002.4")...
Updating package.json with dependency @angular/cli @ "11.2.18" (was "10.2.4")...
Updating package.json with dependency @angular/compiler-cli @ "11.2.14" (was "10.2.5")...
Updating package.json with dependency @angular/language-service @ "11.2.14" (was "10.2.5")...
Updating package.json with dependency karma @ "6.3.11" (was "5.0.9")...
Updating package.json with dependency @angular/animations @ "11.2.14" (was "10.2.5")...
Updating package.json with dependency @angular/common @ "11.2.14" (was "10.2.5")...
Updating package.json with dependency @angular/compiler @ "11.2.14" (was "10.2.5")...
Updating package.json with dependency @angular/core @ "11.2.14" (was "10.2.5")...
Updating package.json with dependency @angular/forms @ "11.2.14" (was "10.2.5")...
Updating package.json with dependency @angular/platform-browser @ "11.2.14" (was "10.2.5")...
Updating package.json with dependency @angular/platform-browser-dynamic @ "11.2.14" (was "10.2.5")...
Updating package.json with dependency @angular/router @ "11.2.14" (was "10.2.5")...
UPDATE package.json (2808 bytes)
⠧ Installing packages (npm)...npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: stacked@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.18" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! dev @angular-devkit/build-angular@"~0.1102.18" from the root project
npm ERR!
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.18
npm ERR! node_modules/@angular-devkit/build-angular
npm ERR! dev @angular-devkit/build-angular@"~0.1102.18" 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 C:\Users\leino\AppData\Local\npm-cache\eresolve-report.txt for a full report.npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\leino\AppData\Local\npm-cache_logs22-01-14T16_41_50_262Z-debug.log✖ Package install failed, see above.
× Migration failed. See above for further details.
我知道使用 --force
参数是个坏主意,但更喜欢在 angular 更新后解决对等依赖关系,而不是在每个版本上解决。
拜托,有人知道吗?
从 8 级升级到 13 级!!这就是我要做的!
使用
卸载全局@angular/cli
sudo npm uninstall -g @angular/cli
使用
安装最新的angular cli 全球版本sudo npm install -g @angular/cli
使用
检查安装的全球版本sudo npm list -g depth0
创建新项目使用
sudo ng new yourProjectName
删除
node_modules
文件夹和package-lock.json file
移动您的旧项目文件(不要覆盖
angular.json
或package.json
文件,而是从您的旧项目中移动非 angular npm 包package.json
到你的新项目package.json
文件)运行
sudo npm install
运行
ng serve
解决您的应用错误
祝你好运
我今天遇到了完全相同的问题。我就是这样修复它的:
npx @angular/cli@11 update @angular/core@11 @angular/cli@11 --force
# now getting the same errors as above
npm install @angular-devkit/build-angular@~0.1102.18 --force
git checkout -- .
npx @angular/cli@11 update @angular/core@11 @angular/cli@11 --force
现在转到 package.json
并删除包含 @angular-devkit/build-ng-packagr
.
执行这行:
rm package-lock.json
rm -rf node_modules
npm install
完成!
也许从 package.json 加上 npm install
中删除该特定行就足够了,上面的其他命令在不必要的地方但我宁愿告诉你我所做的一切:)
顺便说一下,在我尝试所有这些之前,我也按照上面的评论之一降级到 npm v7,但我认为这没有必要或没有任何帮助。
我刚遇到这个问题,运行这个命令帮我解决了:
npm install @angular-devkit/build-angular@~0.1102.18 --force
找到了! 那是我的节点版本的问题。我正在使用 v16.9 并安装节点 v14.19 解决了我的问题。
我借此机会安装了 windows-nvm 以便能够管理许多节点版本。
- 卸载节点
- 安装windows-nvmhttps://github.com/coreybutler/nvm-windows
- 使用节点 v14.19
- 升级到 angular 11 !
从版本 10 到 11 的主要区别在于 Angular 的模块 @angular-devkit/build-angular 及其相关的依赖项已移至单个模块。
你会注意到@angular-devkit/build-angular@0.1002.4变成了@angular-devkit/build-angular@semantic-versioning-that-aligns-with-the-rest-of-the-other-angular-modules.
话虽如此,您需要对 angular.json 和其他配置文件进行一些更改。 最简单的事情(在 运行 npx 更新之后)是创建一些临时 hello-world 项目,然后比较所有配置文件
版本 11 到 12 似乎更直接。然后从版本 12 到 13,他们需要你拥有 NodeJs 版本 12.20.0 或更高版本。例如,您可能需要进行一些代码调整:如果您使用 Service Workers 之类的东西,因为某些方法已被弃用。