Обновление с Angular 12 до 14 не работает

Я хочу обновить этот код до Angular 14 с 12, но не работает:

https://github.com/PacktPublishing/Reactive-Patterns-with-RxJS-for-Angular/tree/main/Chapter04

npm installтерпит неудачу с:

      npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: recipes-book@0.0.0
npm ERR! Found: rxjs@7.5.4
npm ERR! node_modules/rxjs
npm ERR!   rxjs@"7.5.4" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer rxjs@"^6.5.3" from @angular/core@12.1.5
npm ERR! node_modules/@angular/core
npm ERR!   @angular/core@"~12.1.1" from the root project
npm ERR!   peer @angular/core@"12.1.5" from @angular/animations@12.1.5
npm ERR!   node_modules/@angular/animations
npm ERR!     @angular/animations@"~12.1.1" 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.

ng updateдает:

      Using package manager: npm
Collecting installed dependencies...
Found 0 dependencies.
    We analyzed your package.json, there are some packages to update:
    
      Name                               Version                  Command to update
     --------------------------------------------------------------------------------
      @angular/cdk                       12.2.13 -> 13.3.9        ng update @angular/cdk@13
      @angular/cli                       12.1.4 -> 13.3.9         ng update @angular/cli@13
      @angular/core                      12.1.5 -> 13.3.9         ng update @angular/core@13

Все команды обновления терпят неудачу с сообщением вроде этого:

      $ ng update @angular/cdk@13
The installed Angular CLI version is outdated.
Installing a temporary Angular CLI versioned 13.3.9 to perform the update.
✔ Packages successfully installed.
Using package manager: 'npm'
Collecting installed dependencies...
Found 0 dependencies.
Package '@angular/cdk' is not a dependency.

ng versionпоказывает:

      Angular CLI: 14.2.1
Node: 16.17.0
Package Manager: npm 8.15.0 
OS: linux x64

Angular: <error>
... animations, cdk, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1402.1 (cli-only)
@angular-devkit/build-angular   <error>
@angular-devkit/core            14.2.1 (cli-only)
@angular-devkit/schematics      14.2.1 (cli-only)
@angular/cli                    14.2.1 (cli-only)
@schematics/angular             14.2.1 (cli-only)
rxjs                            6.6.7 (cli-only)
typescript                      <error>

Как я могу обновить этот источник до Angular 14?

1 ответ

НПМ не сломан. Это говорит вам, что вы специально запросили RxJS 7.5.4 вместе с Angular 12.1.5, который поддерживает только RxJS 6. Если бы, например, был удален метод из RxJS 7, Angular попытался бы его вызвать, и проект был бы нарушен.

Правильным способом, конечно, было бы понизить версию RxJS, которую вы запрашиваете в.

Неверным способом было бы указать NPM отказаться от всех проверок зависимостей:. Это часто приводит к поломке приложения.

Золотая середина — дать указание NPM отбрасывать определенные проверки зависимостей, если вы знаете, что все в порядке. В данном конкретном случае Angular на самом деле совместим с RxJS 7, они просто начали официально поддерживать его позже. Таким образом, мы можем указать NPM переопределить одноранговую зависимость Angular от RxJS:

пакет.json
      {
  ...
  "overrides": {
    // possibly the other Angular packages as well
    "@angular/core": {
      "rxjs": "$rxjs" // use the version from the project instead
    }
  }
}
Другие вопросы по тегам