ChatGPT解决这个技术问题 Extra ChatGPT

What does 'has unmet peer dependency' mean when installing a package with yarn?

I have a fresh install of yarn (via npm install yarn -g) and tried to install a few packages with

yarn add vue-loader babel-loader style-loader css-loader file-loader webpack

I then got a few warnings during the installation, such as

warning "vue-loader@13.3.0" has unmet peer dependency "vue-template-compiler@^2.0.0".

A sister question (about npm) on the same subject yields a few answers which suggest to

update npm remove node_modules as there is a bug in npm about handling dependencies.

I cannot discard the packages in the warnings, as the webpack build fails, which leads to me having to manually install them. At the same time, quite a few dependencies were installed so I do not understand why these were not installed.

What does the above warning mean, and why doesn't yarn install these dependencies on its own?

I am not a native speaker and I have just observed "X has unmet peer dependency Y" message on my laptop. Until I googled this SO question I thought the sentence meant "[installing] X has caused dependencies of Y not to be met", while they mean "X has got unmet peer dependencies..."

T
Tyler Auer

What is a peer dependency

Here is some useful reading on dependency types, and here is info on peer dependencies, but to summarize:

Dependency: A library/package your project needs to run. Peer dependency: Used to indicate a library/package your project will hook in to.

The package vue-loader has a peer dependency on vue-template-compiler - vue-loader acts as a plugin for vue-template-compiler

Why aren't peer dependencies installed by default

Peer dependencies were automatically installed up until npm@3 (which yarn has followed in). This was stopped due to frequently confusing behavior. For example, installing another plugin with a conflicting requirement would result in an error.

We will also be changing the behavior of peerDependencies in npm@3. We won’t be automatically downloading the peer dependency anymore. Instead, we’ll warn you if the peer dependency isn’t already installed. This requires you to resolve peerDependency conflicts yourself, manually, but in the long run this should make it less likely that you’ll end up in a tricky spot with your packages’ dependencies. [Feb 13, 2015]

Update

As per here npm@7 now installs peer dependencies.
For the motivation behind this decision see here


It's just a warning but normally if a dependency is not met the execution will fail. So why does it seem possible to just ignore this warning?
What am I supposed to do? I'm using yarn. Should I ignore this or manually install?? You have only mentioned about npm's update not about yarn. Question is about yarn.
Nothing about yarn! The question is for yarn not npm.
@JeanPaul 2 possible reasons. Firstly if the peer dependency is optional. Secondly if the peer dependency is a dependency of some other installed package, but not listed in package.json, you'll still see the warning even though the package is available.
l
lcapra

Running yarn install --check-files or just yarn install can fix the issue and install the missing depecendencies.

Explicitly adding to your package.json may also be an option.

Reference https://github.com/yarnpkg/yarn/issues/4594#issuecomment-763475899