Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yet another "unmet peer dependency" question

I still don't understand this, despite reading many SO questions and docs. So if this is really a dup, please feel free to point me to anywhere that will explain it.

After adding firebase to my Vue.js project using yarn, I get lots of:

warning "firebase > @firebase/[email protected]" has unmet peer dependency "@firebase/[email protected]".
warning "firebase > @firebase/[email protected]" has unmet peer dependency "@firebase/[email protected]".
warning "firebase > @firebase/[email protected]" has unmet peer dependency "@firebase/[email protected]".
warning "firebase > @firebase/[email protected]" has unmet peer dependency "@firebase/[email protected]".
warning "firebase > @firebase/[email protected]" has unmet peer dependency "@firebase/[email protected]".
warning "firebase > @firebase/auth > @firebase/[email protected]" has unmet peer dependency "@firebase/[email protected]".

I do already have @firebase/[email protected] installed, as a dependency (listed in my yarn.lock but not in package.json). I can resolve these errors by manually doing yarn add @firebase/app-types but I don't see why I need to do that -- I don't ever call anything from @firebase/app-types directly in my app. If firebase depends on it, and it's already installed, why do I get this error? I guess I don't really understand what an unmet "peer dependency" really means. Is this really a problem in firebase (@5.8.4) itself?

I've read through https://yarnpkg.com/lang/en/docs/dependency-types/, which says "Peer dependencies are a special type of dependency that would only ever come up if you were publishing your own package." but clearly it's coming up for me, despite not publishing my own package -- I'm working on an app. I'd appreciate any light shed on this topic!

like image 673
GaryO Avatar asked Feb 25 '19 16:02

GaryO


People also ask

What does unmet Peer dependency mean?

UNMET PEER DEPENDENCY error is thrown when the dependencies of one or more modules specified in the package. json file is not met. Check the warnings carefully and update the package. json file with correct versions of dependencies.

How do you resolve peer dependencies?

Peer dependencies are resolved from dependencies installed higher in the dependency graph, since they share the same version as their parent. That means that if [email protected] has two peers ( bar@^1 and baz@^1 ) then it might have multiple different sets of dependencies in the same project.

How do you install unmet Peer dependency yarn?

Usage. Run npm install (or yarn install ) to install prod and dev , as well as peer dependencies. You still may see "unmet peer dependency" warnings, due to installation flow of npm/yarn. Also it won't update lock (shrinkwrap) files or modify package.

Are peer dependencies required?

When to use peerDependencies? Peer dependencies really come into play when you're developing code that will be used by others, such as plugins and packages. If you're just working on a final product (i.e one that can't really be used inside another project), then you don't really have to worry about it.


1 Answers

A "peer dependency" is best understood as a soft dependency link between a plugin and the software to which it adds functionality.

If every plugin specified a hard dependency on the main software, then you'd be in versioning hell (worse than now).

A "peer dependency" allows a firebase plugin (for example) to hint at which version of firebase it works with by naming a peer dependency.

They are so-called because neither party is the "owner" of the relationship, it's a symbiosis, the package with the extra features only woks with a finite range of versions of the "host" package.

I can resolve these errors by manually doing yarn add @firebase/app-types but I don't see why I need to do that -- I don't ever call anything from @firebase/app-types directly in my app.

Because the "peer dependency" is a hint, nothing will install those dependencies for you, they are more like suggestions. Unfortunately it's up to you to know if you need that thing or not, and whether that warning makes sense.

You may be a victim of this bug https://github.com/yarnpkg/yarn/issues/4850 which is referencing an issue with the app-types package being required also in non-TypeScript packages.

You didn't include a language tag on your post so it's not possible to know whether you are using JavaScript or TypeScript, but if you are using TypeScript you should probably add that package as a development dependency.

That's the meaning of a peer dependency, the tooling cannot know for sure if you need that thing, and not having met all your dependents optional (peer) dependencies might be breaking something, hence the [warning].

You may want to read https://github.com/firebase/firebase-js-sdk/issues/1207#issuecomment-424804228 and note that there's no black and white answer to this, it seems to be highly subjective.

like image 57
Lee Hambley Avatar answered Oct 02 '22 03:10

Lee Hambley