NPM / Yarn suppress unmet dependencies warning if dependency is globally installed
Asked Answered
S

2

8

Whilst installing packages with Yarn I get the following warning

warning Unmet peer dependency "webpack@1 || 2 || ^2.1.0-beta || ^2.2.0-rc"

Even though I have webpack installed globally.

How do I suppress this warning or do I just have to installed it within the project?

Here is my npm list -g --depth=0 output

npm list -g --depth=0
/usr/local/lib
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]

Thanks

Spadix answered 1/3, 2017 at 20:52 Comment(4)
Is there a reason you don't want to install it within the project?Charis
I guess so I don't have it installed twice? I'm still relatively new to npm/yarn etc. Is this normal practice?Spadix
Generally speaking, yes. The reason is twofold: 1. Most projects don't live on one computer forever; eventually you or a teammate will want to install it somewhere that doesn't have the same global packages as your computer, and 2. Most developers have more than one project going at once, and inevitably they'll have two projects that depend on different versions of the same package.Charis
Makes sense, thanks for the help!Spadix
M
7

How do I suppress this warning

Right now there seems to be no way to mute this. There's an open issue on github

or do I just have to install it within the project?

Peer dependencies mean that you need to install it yourself. This is so that the package that you can update your dependency without waiting for the package that uses it to be updated. As an example, webpack-dev-server would depend on a certain version range of webpack, but you can update to a new minor version of webpack (e.g. a bug fix) without worrying about webpack-dev-server breaking. This way you if some other package depends on a later version of webpack than webpack-dev-server does, you do not end up with 2 conflicting versions of webpack. More info here

Monson answered 21/6, 2019 at 19:24 Comment(1)
Looks like this is fixed in v2 of Yarn. But for many, that's not an option. E.g. react-native doesn't support yarn v2 yet.Montfort
A
0

Specific warnings can now be suppressed by using logFilters option in .yarnrc.yml config:

logFilters: [{
  code: 'YN0002',
  level: 'discard'
}]

And yes, the option looks like it belongs in json config but you have to add it to .yarnrc.yml yaml config.

logFilters documentation

Ardyce answered 26/9, 2024 at 9:46 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.