angular 11 的“npm i ngx-slick-carousel”出现错误

Posted

技术标签:

【中文标题】angular 11 的“npm i ngx-slick-carousel”出现错误【英文标题】:I am getting error while "npm i ngx-slick-carousel" with angular 11 【发布时间】:2021-08-08 18:46:08 【问题描述】:

我在执行“npm i ngx-slick-carousel --save”时遇到错误

我的版本是:

$ npm -v
7.6.1

$ node -v
v14.17.0

Angular CLI: 11.2.13

错误是:

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: irt-official@0.0.0
npm ERR! Found: @angular/common@11.2.14
npm ERR! node_modules/@angular/common
npm ERR!   @angular/common@"~11.2.13" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer @angular/common@"^7.0.0 || ^8.0.0 || ^9.0.0" from ngx-slick-carousel@0.5.1
npm ERR! node_modules/ngx-slick-carousel
npm ERR!   ngx-slick-carousel@"*" 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.
npm ERR!
npm ERR! See C:\Users\malik\AppData\Local\npm-cache\eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\malik\AppData\Local\npm-cache\_logs\2021-05-19T14_13_57_035Z-debug.log

package.json:

"@angular/animations": "~11.2.13",
"@angular/common": "~11.2.13",
"@angular/compiler": "~11.2.13",
"@angular/core": "~11.2.13",
"@angular/forms": "~11.2.13",
"@angular/platform-browser": "~11.2.13",
"@angular/platform-browser-dynamic": "~11.2.13",
"@angular/router": "~11.2.13",
"angular-animations": "^0.11.0",
"jquery": "^3.6.0",
"rxjs": "~6.6.0",
"slick-carousel": "^1.8.1",
"tslib": "^2.0.0",
"zone.js": "~0.11.3"

请帮我解决这个问题。为什么我无法安装这个。谢谢

更新 1:

我已删除 node_module 和 packagelock.json 文件并尝试执行“npm install”,但现在出现此错误

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: irt-official@0.0.0
npm ERR! Found: @angular/core@11.2.14
npm ERR! node_modules/@angular/core
npm ERR!   @angular/core@"~11.2.13" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer @angular/core@"12.0.1" from @angular/animations@12.0.1
npm ERR! node_modules/@angular/animations
npm ERR!   peer @angular/animations@">=6.0.0" from angular-animations@0.11.0
npm ERR!   node_modules/angular-animations
npm ERR!     angular-animations@"^0.11.0" 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.
npm ERR!
npm ERR! See C:\Users\malik\AppData\Local\npm-cache\eresolve-report.txt

获取完整报告。

更新 2:

我已经完成“npm install --legacy-peer-deps”这个命令安装了我的 node_module,但是当我在安装后执行“ng serve”时,我收到了这个错误

发生未处理的异常:目标入口点“@angular/platform-b​​rowser/animations”缺少依赖项:

@angular/动画 @angular/animations/browser

更新 3:

我已经完全刷新了所有东西,比如我已经卸载了 node 和 angular cli 并重新安装了

节点版本16.2.0

npm -v: 7.6.1

Angular CLI:12.0.1

现在我创建了新项目“ng new IRT-Official” 然后我再次尝试执行“npm install ngx-slick-carousel --save” 现在我收到此错误。

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: irt-official@0.0.0
npm ERR! Found: @angular/common@12.0.1
npm ERR! node_modules/@angular/common
npm ERR!   @angular/common@"~12.0.1" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer @angular/common@"^7.0.0 || ^8.0.0 || ^9.0.0" from ngx-slick-carousel@0.5.1
npm ERR! node_modules/ngx-slick-carousel
npm ERR!   ngx-slick-carousel@"*" 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 

更新 4:

我在我的 packege.json 文件中手动添加了“ngx-slick-carousel”:“0.5.1”,然后“npm install --legacy-peer-deps”它安装了 crousal,但是当我完成所有步骤时,我收到类似的错误

未捕获的类型错误:$(...).owlCarousel 不是函数

【问题讨论】:

好的,我要编辑并以文本形式分享 这能回答你的问题吗? Fix the upstream dependency conflict installing NPM packages @MauricioGraciaGutierrez 我已经尝试运行“npm install --legacy-peer-deps”但仍然出现同样的错误 尝试以下“npm install @angular/animations@latest --save”,每当您遇到新错误时,请在 SO 或 google 中查找 - ***.com/questions/42857345/… - 从一个错误转移到另一个错误是进展 @MauricioGraciaGutierrez 请检查有问题的更新 3。 【参考方案1】:

您可以通过在节点模块中编辑来解决这个问题. 问题是,在将其投入生产之前,您还必须对多段代码进行安全测试和单元测试——或者无论如何,您可能应该找到一个保持最新状态的轮播模块。

任何你看到@angular的地方都改到下面

“^7.0.0 || ^8.0.0 || ^9.0.0 || ^10.0.0 || ^11.0.0”

【讨论】:

您好,亲爱的。我已经确认我从 @Angular 开始的所有东西都是 11.2.13 不,它应该是光滑的轮播而不是你的 package.json 的角度。此错误行告诉我们问题出在哪里 @angular/common@"^7.0.0 || ^8.0.0 || ^9.0.0" 来自 ngx-slick-carousel@0.5.1 尝试删除 node_modules 文件夹并重新安装- 因为我查看了 git 并且它具有正确的版本树 - 这意味着我认为安装有问题,有时会损坏 - 角度很挑剔。 或 npm install @angular/cli@11.2.14 @angular/common@11.2.14 ngx-slick-carousel@latest 没有任何效果。即使我尝试过使用旧版本的 angular。你能帮我使用 Team viewer 吗? 我知道有紧急事项并依靠书面答复可能会很痛苦,但请不要要求远程支持,我们不是呼叫中心。【参考方案2】:

更新

您似乎没有从https://www.npmjs.com/package/ngx-slick-carousel运行安装步骤

以前的

你的 package.json 正在寻找 "@angular/common": "~11.2.13" 但你安装的是 11.2.14 版本

将你的 package.json 更新为

   "@angular/common": "^11.2.13"

   "@angular/common": "^11.2.14"

What's the difference between tilde(~) and caret(^) in package.json?

【讨论】:

我试过了,但没用。你能帮我看看团队查看器吗? 是否出现同样的错误?不同的错误?请更新您的问题。 (无法远程帮助您) 我已经卸载了 Angular CLi 并再次安装了我的 Angular cli 版本是 12.0.1 我更新了我的新错误问题 我认为我的 nodejs 有问题。因为我有很多项目,我在删除 node_module 和 packagelock.json 文件后尝试“npm install”,我无法在任何项目中安装。我应该告诉你即使在这个项目中的错误我也无法执行“npm install” 我正在按照这些步骤进行操作。前两次安装没有问题,但第三次安装 ngx crousal 时遇到问题

以上是关于angular 11 的“npm i ngx-slick-carousel”出现错误的主要内容,如果未能解决你的问题,请参考以下文章

编译 Angular 11(从 Angular 9 升级)应用程序时出错

查看页面源 Angular Universal 和 Angular 11

Angular 11 单元测试代码覆盖率现已突破

Angular 11字体内联失败

Angular 11 tsconfig 路径别名无法识别

从 Angular 11 升级到 12 会导致对等依赖冲突