为使用 `ng new` 创建的 Angular 项目手动设置库版本

问题描述 投票:0回答:1

我使用 Node

v18.18.2
@angular/[email protected]
使用
ng new
命令创建了一个 Angular 项目。

rxjs ~7.8.0 出现在 package.json 中

  "dependencies": {
    "@angular/animations": "^15.2.0",
    "@angular/common": "^15.2.0",
    "@angular/compiler": "^15.2.0",
    "@angular/core": "^15.2.0",
    "@angular/forms": "^15.2.0",
    "@angular/platform-browser": "^15.2.0",
    "@angular/platform-browser-dynamic": "^15.2.0",
    "@angular/router": "^15.2.0",
    "rxjs": "~7.8.0",
    "tslib": "^2.3.0",
    "zone.js": "~0.12.0",
    "spa-ui-common": "spa-ui-common-2.0.6.tgz"
  },

我的项目依赖于一个支持 Angular 15 的模块。下面是 package.json 的一部分

  "dependencies": {
    "@angular/animations": "^15.2.9",
    "@angular/cdk": "^15.2.9",
    "@angular/common": "^15.2.9",
    "@angular/compiler": "^15.2.9",
    "@angular/core": "^15.2.9",
    "@angular/forms": "^15.2.9",
    "@angular/localize": "^15.2.9",
    "@angular/material": "^15.2.9",
    "@angular/platform-browser": "^15.2.9",
    "@angular/platform-browser-dynamic": "^15.2.9",
    "@angular/router": "^15.2.9",
    "@babel/core": "^7.21.8",
    "@electron/remote": "2.0.10",
    "@fortawesome/angular-fontawesome": "^0.10.0",
    "@fortawesome/fontawesome-svg-core": "6.4.0",
    "@fortawesome/free-regular-svg-icons": "5.13.0",
    "@fortawesome/free-solid-svg-icons": "5.13.0",
    "@ng-bootstrap/ng-bootstrap": "^14.2.0",
    "@popperjs/core": "^2.11.7",
    "bootstrap": "^4.6.1",
    "core-js": "3.30.0",
    "file-saver": "^2.0.5",
    "font-awesome": "^4.7.0",
    "handlebars": "^4.7.7",
    "lodash": "^4.17.21",
    "moment-mini": "^2.29.4",
    "moment-timezone": "^0.5.43",
    "papaparse": "^5.4.1",
    "rxjs": "^6.5.5",

将模块添加到 package.json 并运行

npm install
后,发现
rxjs

存在冲突

下午 错误!找到:[电子邮件受保护] npm 错误!节点模块/rxjs npm 错误! rxjs@"~7.8.0" 来自根项目 npm 错误!对等 rxjs@"^6.5.3 || ^7.4.0" 来自 @angular/[电子邮件受保护]

~7.8.0 来自我的项目,^6.5.5 来自模块。

据我所知,Angular 15 支持 rxjs ^6.5.3 || ^7.4.0 https://angular.io/guide/versions

那么我可以手动更改项目package.json中的rxjs版本,如^6.5.3来消除兼容性问题吗?

谢谢

angular angular-cli package.json
1个回答
0
投票

您绝对可以更改 package.json 文件中的版本。可能发生的最糟糕的事情是您遇到另一个依赖项错误,而您已经遇到了该错误,

应该注意的是,从 ^6.5.5 更改为 ^6.5.3 对实际安装的软件包没有影响,因为它们都应该使用最高的可用 6.x.x

即使 package.json 文件已降级,您的项目似乎仍然安装了 7.8.1。我会快速检查 package-lock.json 以确保它具有正确的版本,然后一定要检查您的 node_modules 文件夹,因为该项目不是全局的。

转到 rxjs 文件夹并查看 package.json,它将显示已安装的确切版本。如果它仍然是 7.x.x 那么您需要重新安装您的软件包。如果是 6.x.x,它可能会更接近 6.6.7,因为 ^ 允许进行次要更新和补丁更新。

© www.soinside.com 2019 - 2024. All rights reserved.