npm install --legacy-peer-deps 到底做了什么?什么时候推荐/什么是潜在用例? [英] What does npm install --legacy-peer-deps do exactly? When is it recommended / What's a potential use case?

查看:559
本文介绍了npm install --legacy-peer-deps 到底做了什么?什么时候推荐/什么是潜在用例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

刚遇到这个错误:

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: nexttwin@0.1.0
npm ERR! Found: react@17.0.1
npm ERR! node_modules/react
npm ERR!   react@"17.0.1" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^16.8.0" from react-hook-mousetrap@2.0.4
npm ERR! node_modules/react-hook-mousetrap
npm ERR!   react-hook-mousetrap@"*" from the root project
npm ERR! 

我尝试安装的模块似乎与我安装的模块具有不同的对等依赖项.似乎 npm 在这方面改变了它的行为,现在让安装失败.

The module I am trying to install seems to have a different peer dependency from what I have installed. It seems like npm changed its behaviour in this regard and now lets the install fail.

我现在可以做些什么来解决这个问题?我不想为此降级我的 React 版本.

What can I do now to fix this? I don't want to downgrade my React version for this.

我知道有一个名为 --legacy-peer-deps 的标志,但我不确定这到底是做什么的,是否建议使用它/潜在的缺点是什么?我认为 npm 确实让安装失败是有原因的.

I know there is a flag called --legacy-peer-deps but I am not sure what exactly this does and whether it's recommended to use it / what the potential disadvantages are? I assume there is a reason npm did let the install fail.

这很奇怪,因为直到最近我还在使用 yarn 并且一切都很好.

It's just strange because I was using yarn up until very recently and everything was fine.

推荐答案

我是这样解决这个问题的:

Here's how I solved this problem:

首先,发生了什么: react-hook-mousetrap 正在寻找 react@16.8.0,但没有找到.相反,它正在寻找@react17.0.1,这是一个较新的版本.出于某种原因,捕鼠器不喜欢这个新版本,您会收到通知(这没什么大不了,但他们认为值得停止您的构建).

First, what's happening: react-hook-mousetrap is looking for react@16.8.0, but it is not finding it. Instead it is finding @react17.0.1, which is a newer version. For some reason mousetrap doesn't like this newer version, and you are being notified (it is not a big deal, but they decided it was worth stopping your build).

一种解决方案:强行安装mousetrap想要的特定版本的react:

One solution: forcibly install the specific version of react that mousetrap wants:

yarn install react@16.8.0

这样做是将您的反应版本回滚到与捕鼠器兼容的稍旧版本.您不会注意到任何差异,并且在未来的迭代中,希望捕鼠器得到更新,因此这种情况会消失.

What this does is roll back your react version to a slightly older one that is compatible with mousetrap. You won't notice any difference, and in future iterations, hopefully mousetrap is updated, so this goes away.

另一种解决方案:彻底决定不安装任何旧版本的依赖项:

Another solution: make a sweeping decision to not install any older version dependencies:

npm install xxxx --legacy-peer-deps

这样做是忽略此包的旧依赖项.它更全面,并为您做出很多决定.

What this does is ignore old dependencies for this package. It is more comprehensive, and makes a lot of the decisions for you.

这篇关于npm install --legacy-peer-deps 到底做了什么?什么时候推荐/什么是潜在用例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆