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

查看:8987
本文介绍了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).

一种解决方案::强制安装捕鼠器想要的特定版本的反应:

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天全站免登陆