【问题标题】:Unable to upgrade from angular 12 to angular 13无法从 Angular 12 升级到 Angular 13
【发布时间】:2021-11-14 10:02:57
【问题描述】:

我有一个 Angular 12 应用程序,我正在尝试升级到 Angular 13。

根据https://update.angular.io/?l=2&v=12.0-13.0我应该跑:

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

但是当我这样做时,我收到以下错误:

npx @angular/cli@13 update @angular/core@13 @angular/cli@13
The installed local Angular CLI version is older than the latest stable version.
Installing a temporary version to perform the update.
✔ Package successfully installed.
Using package manager: 'npm'
Collecting installed dependencies...
Found 38 dependencies.
Fetching dependency metadata from registry...
    Updating package.json with dependency @angular-devkit/build-angular @ "13.0.2" (was "12.1.1")...
    Updating package.json with dependency @angular/cli @ "13.0.2" (was "12.1.1")...
    Updating package.json with dependency @angular/compiler-cli @ "13.0.1" (was "12.1.1")...
    Updating package.json with dependency typescript @ "4.4.4" (was "4.3.5")...
    Updating package.json with dependency @angular/animations @ "13.0.1" (was "12.1.1")...
    Updating package.json with dependency @angular/common @ "13.0.1" (was "12.1.1")...
    Updating package.json with dependency @angular/compiler @ "13.0.1" (was "12.1.1")...
    Updating package.json with dependency @angular/core @ "13.0.1" (was "12.1.1")...
    Updating package.json with dependency @angular/forms @ "13.0.1" (was "12.1.1")...
    Updating package.json with dependency @angular/platform-browser @ "13.0.1" (was "12.1.1")...
    Updating package.json with dependency @angular/platform-browser-dynamic @ "13.0.1" (was "12.1.1")...
    Updating package.json with dependency @angular/router @ "13.0.1" (was "12.1.1")...
  UPDATE package.json (1566 bytes)
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: scrum-poker-app@0.0.0
npm ERR! Found: @angular-devkit/build-angular@12.1.1
npm ERR! node_modules/@angular-devkit/build-angular
npm ERR!   dev @angular-devkit/build-angular@"~13.0.2" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! dev @angular-devkit/build-angular@"~13.0.2" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: @angular/compiler-cli@13.0.1
npm ERR! node_modules/@angular/compiler-cli
npm ERR!   peer @angular/compiler-cli@"^13.0.0" from @angular-devkit/build-angular@13.0.2
npm ERR!   node_modules/@angular-devkit/build-angular
npm ERR!     dev @angular-devkit/build-angular@"~13.0.2" 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!

✖ Package install failed, see above.

我也尝试使用--force 标志,它可以工作,但是当我执行npm install 时,我得到了这个:

npm install
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: scrum-poker-app@0.0.0
npm ERR! Found: @angular-devkit/build-angular@12.1.1
npm ERR! node_modules/@angular-devkit/build-angular
npm ERR!   dev @angular-devkit/build-angular@"~13.0.2" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! dev @angular-devkit/build-angular@"~13.0.2" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: @angular/compiler-cli@13.0.1
npm ERR! node_modules/@angular/compiler-cli
npm ERR!   peer @angular/compiler-cli@"^13.0.0" from @angular-devkit/build-angular@13.0.2
npm ERR!   node_modules/@angular-devkit/build-angular
npm ERR!     dev @angular-devkit/build-angular@"~13.0.2" 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.

知道我错过了什么吗?

编辑 我当前的 package.json

{
  "name": "scrum-poker-app",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "watch": "ng build --watch --configuration development",
    "test": "ng test"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~12.1.0",
    "@angular/cdk": "^12.1.1",
    "@angular/common": "~12.1.0",
    "@angular/compiler": "~12.1.0",
    "@angular/core": "~12.1.0",
    "@angular/fire": "^6.1.5",
    "@angular/forms": "~12.1.0",
    "@angular/platform-browser": "~12.1.0",
    "@angular/platform-browser-dynamic": "~12.1.0",
    "@angular/router": "~12.1.0",
    "@datorama/akita": "^6.2.0",
    "@datorama/akita-ng-router-store": "^6.0.0",
    "@firebase/firestore-types": "^2.3.0",
    "akita-ng-fire": "^6.0.0",
    "date-fns": "^2.22.1",
    "firebase": "^8.7.0",
    "firebaseui": "^4.8.0",
    "firebaseui-angular": "^5.1.3",
    "ngx-date-fns": "^8.1.0",
    "primeflex": "^2.0.0",
    "primeicons": "^4.1.0",
    "primeng": "^12.0.0",
    "rxjs": "~6.6.0",
    "tslib": "^2.2.0",
    "zone.js": "~0.11.4"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~12.1.0",
    "@angular/cli": "~12.1.0",
    "@angular/compiler-cli": "~12.1.0",
    "@datorama/akita-ngdevtools": "^6.0.0",
    "@types/jasmine": "~3.6.0",
    "@types/node": "^12.11.1",
    "jasmine-core": "~3.7.0",
    "karma": "~6.3.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage": "~2.0.3",
    "karma-jasmine": "~4.0.0",
    "karma-jasmine-html-reporter": "^1.5.0",
    "typescript": "~4.3.2"
  }
}

【问题讨论】:

  • 请提供您的package.json文件
  • @AlexElin 我添加了抱歉
  • 你能提供你的npm 版本吗?我看到 npm 7 github.com/angular/angular-cli/issues/19957 存在问题。也许他们在某种程度上与你的情况有关
  • @AlexElin NPM 8.1.0
  • @Vega 正如我提到的,我尝试了强制选项,没有帮助

标签: angular angular-upgrade


【解决方案1】:

这似乎是 npm 的问题

我有 "npm --version" --> 8.5.4 但提到版本 7.x 产生相同的错误

这里解决了这个问题: https://github.com/angular/angular-cli/issues/21204

建议的解决方法是:

  • 将 --force 选项传递给 ng update,这会将 force 标志传播到 npm。
  • 降级到 npm 6
  • 切换到 yarn 作为包管理器

我用的是第一个:

npm i
npx @angular/cli@13 update @angular/core@13 @angular/cli@13 --force

【讨论】:

    【解决方案2】:

    同样的问题。只有在我做了npm install 之后,我才能从 angular 12 升级到 angular 13.2。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-06-18
      • 1970-01-01
      • 2022-08-11
      • 2022-07-08
      • 2021-11-18
      • 2020-02-01
      • 1970-01-01
      • 2023-03-18
      相关资源
      最近更新 更多