Javascript 使用 Yarn 安装软件包时,“不正确的对等依赖项”是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42361942/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 01:05:37  来源:igfitidea点击:

When installing packages with Yarn, what does "incorrect peer dependency" mean?

javascriptdependenciesdependency-managementnode-modulesyarnpkg

提问by shrewdbeans

I'm just cloned a repo, which recommends the use of Yarnto install dependencies. When I run yarn install, it seems to be okay, but it provides this warning:

我只是克隆了一个 repo,它建议使用Yarn来安装依赖项。当我运行时yarn install,它似乎没问题,但它提供了以下警告:

yarn install v0.20.3
[1/4]   Resolving packages...
[2/4]   Fetching packages...
[3/4]   Linking dependencies...
warning "[email protected]" has incorrect peer dependency "node-sass@^3.4.2".
[4/4]   Building fresh packages...
?  Done in 77.59s.

I've looked online to find out exactly what "has incorrect peer dependency" means. But all I can find are reported issues on other repositories or questions about how to fix the problem.

我在网上查看了确切的“具有不正确的对等依赖性”的含义。但我能找到的只是其他存储库上报告的问题或有关如何解决问题的问题。

Can someone explain what this means and why it is only a warning, and not an error?

有人可以解释这意味着什么以及为什么它只是警告而不是错误?

Also, is it something that I should try to address or report to the community behind the repo I have just cloned?

另外,我是否应该尝试向我刚刚克隆的回购背后的社区解决或报告一些问题?

采纳答案by JonnyFoley

It is only a warning as it won't actually stop your code from running, It's just there to give you a heads up that there's something wrong with your dependencies.

这只是一个警告,因为它实际上不会阻止您的代码运行,它只是提醒您您的依赖项存在问题。

Effectively, peer dependencies are a way for packages to specify, "to use me, you should also have x version of y package installed".

实际上,对等依赖是包指定的一种方式,“要使用我,您还应该安装 y 包的 x 版本”。

You should upgrade to the latest versions, see this linkfor more details on sass-loader dependencies

您应该升级到最新版本,有关 sass-loader 依赖项的更多详细信息,请参阅此链接

回答by Flip

I think that there are packages for which it doesn't make a big difference (if not exposed in your app or not likely that conflicting versions create problems, e.g. moment.js), but then there are packages, like React, for which it matters that all React dependencies are compatible with each other as they might create components that have to understand each other.

我认为有些包对它没有太大影响(如果没有在你的应用程序中公开或者冲突的版本不太可能产生问题,例如 moment.js),但是有一些包,比如 React,它重要的是所有 React 依赖项彼此兼容,因为它们可能会创建必须相互理解的组件。

In your case, probably one of your dependencies uses sass-loaderin a different version than you specify in your project.

在您的情况下,您的依赖项之一可能使用sass-loader的版本与您在项目中指定的版本不同。

By declaring it as a peerDependencyyou can tell npm which version your project expects and it will give you a warning (as you saw) when there is a conflict.

通过将其声明为 a,peerDependency您可以告诉 npm 您的项目期望哪个版本,并且在发生冲突时它会向您发出警告(如您所见)。