安装 angular 库 - 无法解析依赖关系树

install angular library - unable to resolve dependency tree

前段时间我将我的通用代码从我的 angular 应用程序中提取到库中。现在看来我无法将针对 @angular/core@13.1 的库安装到新创建的应用程序中,该应用程序也针对 13.1.

图书馆package.json

{
  "name": "@xxx/ng-animations",
  "private": false,
  "version": "13.1.3",
  "peerDependencies": {
    "@angular/common": "^13.1.0",
    "@angular/core": "^13.1.0"
  },
  "dependencies": {
    "tslib": "^2.3.0"
  }
}

全新的应用程序package.json

{
  ...,
  "dependencies": {
    "@angular/animations": "~13.1.0",
    "@angular/common": "~13.1.0",
    "@angular/compiler": "~13.1.0",
    "@angular/core": "~13.1.0",
    "@angular/forms": "~13.1.0",
    "@angular/platform-browser": "~13.1.0",
    "@angular/platform-browser-dynamic": "~13.1.0",
    "@angular/router": "~13.1.0",
    "rxjs": "~7.4.0",
    "tslib": "^2.3.0",
    "zone.js": "~0.11.4"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~13.1.3",
    "@angular/cli": "~13.1.3",
    "@angular/compiler-cli": "~13.1.0",
    "@types/jasmine": "~3.10.0",
    "@types/node": "^12.11.1",
    "jasmine-core": "~3.10.0",
    "karma": "~6.3.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage": "~2.1.0",
    "karma-jasmine": "~4.0.0",
    "karma-jasmine-html-reporter": "~1.7.0",
    "typescript": "~4.5.2"
  }
}

这会导致以下版本冲突错误,我无法解决(我过去解决了其中的一些)

npm i @mintplayer/ng-animations
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: tada@0.0.0
npm ERR! Found: @angular/core@13.1.1
npm ERR! node_modules/@angular/core
npm ERR!   @angular/core@"~13.1.0" from the root project
npm ERR!   peer @angular/core@"^13.1.0" from @mintplayer/ng-animations@13.1.3
npm ERR!   node_modules/@mintplayer/ng-animations
npm ERR!     @mintplayer/ng-animations@"*" from the root project
npm ERR!   1 more (@angular/animations)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer @angular/core@"13.1.2" from @angular/common@13.1.2
npm ERR! node_modules/@angular/common
npm ERR!   @angular/common@"~13.1.0" from the root project
npm ERR!   peer @angular/common@"^13.1.0" from @mintplayer/ng-animations@13.1.3
npm ERR!   node_modules/@mintplayer/ng-animations
npm ERR!     @mintplayer/ng-animations@"*" 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.

我使用的是最新版本的 angular:

> ng version

Angular CLI: 13.1.3
Node: 14.18.2
Package Manager: npm 8.3.0
OS: win32 x64

Angular: 13.1.2
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1301.3
@angular-devkit/build-angular   13.1.3
@angular-devkit/core            13.1.3
@angular-devkit/schematics      13.1.3
@angular/cli                    13.1.3
@schematics/angular             13.1.3
rxjs                            7.4.0
typescript                      4.5.4

> node -v
v14.18.2

> npm -v
8.3.0

我前段时间遇到过类似的问题,但那是我将我的应用程序从 angular 11 升级到 13 时,我能够通过检查特定包 npm 的版本来解决它抱怨。但是现在所有版本都一样(13.x.x 或 13.1.x)。

一切都是针对angular13.1,那么这个错误是从哪里来的呢?非常感谢任何帮助。

您的全局版本是最新的,但不是项目版本。 运行 npx @angular/cli@13 update @angular/core@13 @angular/cli@13 在项目中并再次安装依赖项

另一种选择是使用 --force 标志安装库

我试图安装@angular/service-worker,但它向我展示了类似的问题,我所做的是:

  • 删除 node_modules 包
  • 然后 运行 npm update 而不是 npm install

在 运行 命令 npm update.

之前,我的包 @angular/service-worker 的版本已经在 package.json