130

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

yarn install v0.20.3
[1/4]   Resolving packages...
[2/4]   Fetching packages...
[3/4]   Linking dependencies...
warning "sass-loader@4.0.2" 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?

BinaryButterfly
  • 18,137
  • 13
  • 50
  • 91
shrewdbeans
  • 11,971
  • 23
  • 69
  • 115
  • Potential duplicate: https://stackoverflow.com/questions/46928390/what-does-has-unmet-peer-dependency-mean-when-installing-a-package-with-yarn – Kalinda Pride Jun 16 '21 at 01:00

2 Answers2

51

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

J Foley
  • 1,038
  • 1
  • 17
  • 30
  • 21
    In my project I have: `less: 3.0` and `less-loader: 4.0.5` installed. When running `webpack` I get: `less-loader@4.0.6" has incorrect peer dependency "less@^2.3.1"` Why does he talk about `less-loader@4.0.6` because i have `4.0.5` installed? – Legends Mar 09 '18 at 13:45
  • 4
    It won't stop your code from running? That's 100% dependent on the dependency in question. The only time this answer would be true is with dependences that are 100% backward compatible. If for example, angular which depends on rxjs, depends on some function in rxjs that gets removed in a new version, that complaint is going to mean the app breaks, not just complains. – Derek Greer Aug 10 '22 at 21:25
  • What if I know there are dependency conflicts, serious ones, and I want things to still compile correctly, using the right versions in the right spots? i.e. imagine a 2023 react-bootstrap app shoved into a 2017 large bootstrap 3 app as a library. I would've thought webpack handled this if it can resolve dependencies per use. Is there a solution? – gunslingor Feb 16 '23 at 18:43
8

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.

Lee
  • 676
  • 6
  • 20
Flip
  • 6,233
  • 7
  • 46
  • 75
  • I was wondering whether it's saying the information in the packages package.json has a wrong dependency listed That's where it gets it's information from isn't it? Just from reading package.json files It's not concerning about what node_modules are installed that aren't included in package.json – Mices May 04 '21 at 02:30
  • My react app has an explicit dependency stated on "react": "^17.0.2", but the yarn install shows tons of lines like: ``` warning " > react-hooks-form@2.0.1" has incorrect peer dependency "react@^16.8.0". warning " > react-hooks-form@2.0.1" has incorrect peer dependency "react-dom@^16.8.0". warning " > react-select-search@2.2.4" has incorrect peer dependency "react@^16.8.4". warning " > react-select-search@2.2.4" has incorrect peer dependency "react-dom@^16.8.4". ``` Why is it so upset? – XP84 Jan 10 '23 at 22:18