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

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

yarn install v0.20.3
[1/4] 						

答案 1

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".

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


答案 2

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.

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

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