我应该如何解决这个 Angular 节点包模块依赖冲突?

use*_*050 5 node.js npm npm-install angular

我刚刚使用npm-check-updates更新了所有节点模块。\n我这样做是为了安装最新版本ngx-stripe,它需要一些我尚未安装的更新节点模块。

\n

更新所有节点模块然后尝试安装 ngx-stripe 后,我收到以下错误,显示 ngx-gallery-9@1.0.6 具有 tslib 1.10.0 的对等依赖项,这是正确的,但我安装的版本节点模块中的 tslib 2.5.0 是。

\n

问题- 在为 ngx-stripe 运行 npm install 时,我应该使用 --force 或 --legacy-peer-deps 还是应该先尝试其他操作,例如更新 ngx-gallery-9 的 tslib 对等依赖项?

\n

这是我所看到的:

\n
\xe2\x9e\x9c  client git:(master) \xe2\x9c\x97 npm install ngx-stripe @stripe/stripe-js\nnpm ERR! code ERESOLVE\nnpm ERR! ERESOLVE could not resolve\nnpm ERR! \nnpm ERR! While resolving: ngx-gallery-9@1.0.6\nnpm ERR! Found: tslib@2.5.0\nnpm ERR! node_modules/tslib\nnpm ERR!   tslib@"^2.3.0" from @angular/animations@15.1.2\nnpm ERR!   node_modules/@angular/animations\nnpm ERR!     peerOptional @angular/animations@"15.1.2" from @angular/platform-browser@15.1.2\nnpm ERR!     node_modules/@angular/platform-browser\nnpm ERR!       peer @angular/platform-browser@"15.1.2" from @angular/forms@15.1.2\nnpm ERR!       node_modules/@angular/forms\nnpm ERR!         peer @angular/forms@"^11.2.11 || ^12.0.4 || ^13.0.0 || ^14.0.0 || ^15.0.0" from @zxing/ngx-scanner@3.8.0\nnpm ERR!         node_modules/@zxing/ngx-scanner\nnpm ERR!         2 more (ngx-bootstrap, the root project)\nnpm ERR!       3 more (@angular/platform-browser-dynamic, @angular/router, the root project)\nnpm ERR!     peer @angular/animations@"^15.0.0" from ngx-bootstrap@10.2.0\nnpm ERR!     node_modules/ngx-bootstrap\nnpm ERR!       ngx-bootstrap@"^10.2.0" from the root project\nnpm ERR!     1 more (the root project)\nnpm ERR!   tslib@"^2.3.0" from @angular/common@15.1.2\nnpm ERR!   node_modules/@angular/common\nnpm ERR!     peer @angular/common@"15.1.2" from @angular/forms@15.1.2\nnpm ERR!     node_modules/@angular/forms\nnpm ERR!       peer @angular/forms@"^11.2.11 || ^12.0.4 || ^13.0.0 || ^14.0.0 || ^15.0.0" from @zxing/ngx-scanner@3.8.0\nnpm ERR!       node_modules/@zxing/ngx-scanner\nnpm ERR!         @zxing/ngx-scanner@"^3.8.0" from the root project\nnpm ERR!       2 more (ngx-bootstrap, the root project)\nnpm ERR!     peer @angular/common@"^15.0.0 || ^16.0.0" from @angular/google-maps@15.1.2\nnpm ERR!     node_modules/@angular/google-maps\nnpm ERR!       @angular/google-maps@"^15.1.2" from the root project\nnpm ERR!     10 more (@angular/platform-browser, ...)\nnpm ERR!   20 more (@angular/compiler, @angular/compiler-cli, ...)\nnpm ERR! \nnpm ERR! Could not resolve dependency:\nnpm ERR! peer tslib@"^1.10.0" from ngx-gallery-9@1.0.6\nnpm ERR! node_modules/ngx-gallery-9\nnpm ERR!   ngx-gallery-9@"^1.0.6" from the root project\nnpm ERR! \nnpm ERR! Conflicting peer dependency: tslib@1.14.1\nnpm ERR! node_modules/tslib\nnpm ERR!   peer tslib@"^1.10.0" from ngx-gallery-9@1.0.6\nnpm ERR!   node_modules/ngx-gallery-9\nnpm ERR!     ngx-gallery-9@"^1.0.6" from the root project\nnpm ERR! \nnpm ERR! Fix the upstream dependency conflict, or retry\nnpm ERR! this command with --force or --legacy-peer-deps\nnpm ERR! to accept an incorrect (and potentially broken) dependency resolution.\nnpm ERR! \nnpm ERR! \nnpm ERR! For a full report see:\nnpm ERR! /Users/charles/.npm/_logs/2023-01-27T08_58_58_320Z-eresolve-report.txt\n\nnpm ERR! A complete log of this run can be found in:\nnpm ERR!     /Users/charles/.npm/_logs/2023-01-27T08_58_58_320Z-debug-0.log\n\xe2\x9e\x9c  client git:(master) \xe2\x9c\x97 \n
Run Code Online (Sandbox Code Playgroud)\n

Eli*_*lin 2

您的问题与 完全无关ngx-stripe,但是每当您运行 时npm install,NPM 都会尝试同时修复 package.json 中的所有依赖项,并且因为您遇到 问题ngx-gallery-9,所以所有npm installs 都会失败。您现在可以使用 忽略该错误--legacy-peer-deps,这将告诉 NPM 不要尝试处理对等依赖项,而只是让您安装您想要安装的东西 ( ngx-stripe)。

关于修复错误本身,您在这里无能为力。ngx-gallery-9使用的是旧版本tslib,并且已经很长时间没有更新了。当前有一个未解决的错误,要求库维护者更新他的软件包。

更具体地说,Angular 15 需要tslib@"^2.3.0",但ngx-gallery-9需要tslib@"^1.10.0". 您可以尝试通过在所有未来的 npm 安装期间使用强制它使用最新版本--legacy-peer-deps,以及运行npm install tslib@^2.3.0 --save --legacy-peer-deps手动选择使用较新的版本,这将强制整个项目使用tslib@"^2.3.0"并忽略的ngx-gallery-9抱怨,但有一个强大的可能ngx-gallery-9无法按预期工作。

你最好的选择是

  1. ngx-gallery-9使用与, 或不同的图库
  2. 简单地忽略这个问题。强制使用所有内容tslib@"^2.3.0"npm install tslib@^2.3.0 --save --legacy-peer-deps希望ngx-gallery-9不会出现任何错误,或者
  3. 将 Angular 降级到早期版本(这非常混乱,并且不真正推荐,除非您不打算使用 Angular 15)。

编辑:

  1. 或者撤消所做的所有更改npm-check-updates,然后仅安装ngx-stripe与所有软件包兼容的旧版本。ngx-stripe有一个图表显示根据您的 Angular 版本使用哪个版本,此处:https: //www.npmjs.com/package/ngx-stripe