简体   繁体   English

如何在没有 --legacy-peer-deps 标志的情况下使用 npm install 来解决冲突的对等依赖关系?

[英]How to use npm install without the --legacy-peer-deps flag to resolve a conflicting peer dependency?

I am having trouble with a peer dependcy called zone.js.我遇到了一个名为 zone.js 的对等依赖关系。 Version ^0.8.19 is required for @handsontable/angular but version ~0.10.2 is required for @angular/core and others. @handsontable/angular 需要版本 ^0.8.19,但 @angular/core 和其他需要版本 ~0.10.2。 I get this error message when I try npm install.当我尝试安装 npm 时收到此错误消息。

While resolving: @angular/core@9.0.7
npm ERR! Found: zone.js@0.8.29
npm ERR! node_modules/zone.js
npm ERR!   zone.js@"^0.8.19" from the root project
npm ERR!   peer zone.js@"^0.8.19" from @handsontable/angular@2.0.0
npm ERR!   node_modules/@handsontable/angular
npm ERR!     @handsontable/angular@"2.0.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer zone.js@"~0.10.2" from @angular/core@9.0.7
npm ERR! node_modules/@angular/core
npm ERR!   @angular/core@"~9.0.1" from the root project
npm ERR!   peer @angular/core@"9.0.7" from @angular/animations@9.0.7
npm ERR!   node_modules/@angular/animations
npm ERR!     @angular/animations@"~9.0.1" from the root project
npm ERR!     2 more (@angular/material, @angular/platform-browser)
npm ERR!   10 more (@angular/cdk, @angular/common, @angular/forms, ...)
npm ERR!
npm ERR! Conflicting peer dependency: zone.js@0.10.3
npm ERR! node_modules/zone.js
npm ERR!   peer zone.js@"~0.10.2" from @angular/core@9.0.7
npm ERR!   node_modules/@angular/core
npm ERR!     @angular/core@"~9.0.1" from the root project
npm ERR!     peer @angular/core@"9.0.7" from @angular/animations@9.0.7
npm ERR!     node_modules/@angular/animations
npm ERR!       @angular/animations@"~9.0.1" from the root project
npm ERR!       2 more (@angular/material, @angular/platform-browser)
npm ERR!     10 more (@angular/cdk, @angular/common, @angular/forms, ...)
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.

Attempt #1 Update package.json After deleting package-lock.json and node_modules I tried npm install with the updated version shown below. Attempt #1 Update package.json After deleting package-lock.json and node_modules I tried npm install with the updated version shown below. My understanding is that the ^0.8.19 should include 0.8.19 to <1.0.0.我的理解是 ^0.8.19 应该包括 0.8.19 到 <1.0.0。 Wouldn't 0.10.2 fall in this range? 0.10.2 不会落在这个范围内吗?

 "dependencies": {
    ...
    "zone.js": "^0.8.19"
  },

Attempt #2 --legacy-peer-deps I want to avoid using this flag because this ultimately runs in a pipeline without the flag.尝试#2 --legacy-peer-deps 我想避免使用这个标志,因为它最终在没有标志的管道中运行。 Would updating the command to npm install --legacy-peer-deps be risky or dangerous?将命令更新为 npm install --legacy-peer-deps 是否有风险或危险? I have little experience with pipelines and all the senior devs who set this up quit:(我对管道几乎没有经验,所有设置它的高级开发人员都退出了:(

You have the option to retry with --force to bypass the conflict or --legacy-peer-deps command to ignore peer dependencies entirely.您可以选择使用--force重试以绕过冲突或--legacy-peer-deps命令完全忽略对等依赖项。

By default, In the new version of npm (v7), npm install will fail when it encounters conflicting peerDependencies.默认情况下,在新版本的 npm (v7) 中, npm install在遇到冲突的 peerDependencies 时会失败。 It was not like that before.以前不是这样的。

The differences between the two are below -两者的区别如下——

--legacy-peer-deps : ignore all peerDependencies when installing, in the style of npm version 4 through version 6. --legacy-peer-deps :安装时忽略所有 peerDependencies,采用 npm 版本 4 到版本 6 的样式。

--strict-peer-deps : fail and abort the install process for any conflicting peerDependencies when encountered. --strict-peer-deps :遇到任何冲突的 peerDependencies 时失败并中止安装过程。 By default, npm will only crash for peerDependencies conflicts caused by the direct dependencies of the root project.默认情况下,npm 只会在根项目的直接依赖引起的 peerDependencies 冲突时崩溃。

--force : will force npm to fetch remote resources even if a local copy exists on disk. --force :即使磁盘上存在本地副本,也会强制 npm 获取远程资源。

this cmd finally worked for me... atleast tried it这个 cmd 终于为我工作了......至少试过了

npm install --legacy-peer-deps npm 安装 --legacy-peer-deps

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM