Angular 13 个依赖项

Angular 13 dependencies

我最近(一个月前)将我项目的 angular 更新到版本 13.2.2,出现了一些问题,但可以使它工作并且 运行,正在部署。上周四我开始遇到 ng build 的问题,说我的一个库(为该项目制作)需要 angular 核心的高级版本,因为它在版本 13.3.0 中使用了 angular 动画。所以我没有在我的项目中安装这个版本,在我的库中没有安装版本 13.2.2 中的核心和动画。我的问题是,为什么当 angular 团队发布新版本 (13.3.0)(上周四)时,我的项目会自动要求该版本进行构建。我没有更改任何版本或安装了 npm。我怎样才能让我的项目停止寻找核心 13.3.0.

执行 npm list

时我的库出错
npm ERR! peer dep missing: @angular/core@13.3.0, required by @angular/animations@13.3.0

部署项目时出错

npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: MY_PROJECT@0.8.8
npm ERR! Found: @angular/core@13.2.7
npm ERR! node_modules/@angular/core
npm ERR!   @angular/core@"~13.2.2" from the root project
npm ERR!   peer @angular/core@"~13.2.2" from @MYLIBRARY@0.5.3
npm ERR!   node_modules/@MYLIBRARY
npm ERR!     @MYLIBRARY@"^0.5.3" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer @angular/core@"13.3.0" from @angular/animations@13.3.0
npm ERR! node_modules/@angular/animations
npm ERR!   @angular/animations@"^13.2.2" from the root project
npm ERR!   peer @angular/animations@"^13.2.2" from @MYLIBRARY@0.5.3
npm ERR!   node_modules/@MYLIBRARY
npm ERR!     @MYLIBRARY@"^0.5.3" from the root project

打包我的图书馆:

  "peerDependencies": {
    "@angular/common": "~13.2.2",
    "@angular/core": "~13.2.2",
    "@angular/animations": "^13.2.2",
    "@angular/cdk": "~13.2.2",
    "@angular/material": "^13.2.2"
  },
  "dependencies": {
    "tslib": "^2.3.1"
  }

我的项目包:

 "@angular/animations": "^13.2.2",
 "@angular/cdk": "^13.2.2",
 "@angular/common": "~13.2.2",
 "@angular/compiler": "~13.2.2",
 "@angular/core": "~13.2.2",

与此同时,我删除了项目和库中的 node_modules 和 package-lock.json 以查看它是否修复,但没有。现在我可以看到在 package-lock.json 中提到了 angular 13.3.0。但是为什么我没有做任何更新。

请参阅此节点 js 文档。对你的问题有很好的解释。

https://nodejs.dev/learn/the-package-lock-json-file

在 package.json 中,您可以使用 semver 表示法设置要升级到的版本(补丁或次要版本),例如:

  • 如果你写 ~0.13.0,你只想更新补丁版本:0.13.1 可以,但 0.14.0 不行。
  • 如果你写 ^0.13.0,你想获得不改变最左边 non-zero 数字的更新:0.13.1、0.13.2 等等。
  • 如果你写 ^1.13.0,你将获得补丁和次要版本:1.13.1、1.14.0 等等直到 2.0.0 但不是 2.0.0。
  • 如果你写的是 0.13.0,那就是将要使用的确切版本,总是

将您的 package.json 更改为您想要的确切版本,

 "@angular/animations": "13.2.2",
 "@angular/cdk": "13.2.2",
 "@angular/common": "13.2.2",
 "@angular/compiler": "13.2.2",
 "@angular/core": "13.2.2",