React-apollo: Fresh new install gives unmet peer dependencies warnings with yarn

Created on 20 Aug 2019  路  14Comments  路  Source: apollographql/react-apollo

Intended outcome:

I tried to start a new Apollo project, based on the documentation I issued:

yarn add react react-dom apollo-boost @apollo/react-hooks graphql

Which gave:

warning "@apollo/react-hooks > @apollo/[email protected]" has unmet peer dependency "@types/react@^16.8.0".
warning "@apollo/react-hooks > @apollo/[email protected]" has unmet peer dependency "apollo-client@^2.6.4".
warning "@apollo/react-hooks > @apollo/[email protected]" has unmet peer dependency "apollo-utilities@^1.3.2".
warning " > @apollo/[email protected]" has unmet peer dependency "@types/react@^16.8.0".
warning " > @apollo/[email protected]" has unmet peer dependency "apollo-client@^2.6.4".

Actual outcome:

I would expect either no warnings or those peer deps being mentioned in the documentation

Note that with npm instead of yarn, I only get those warnings:

npm WARN @apollo/[email protected] requires a peer of @types/react@^16.8.0 but none is installed. You must install peer dependencies yourself.
npm WARN @apollo/[email protected] requires a peer of @types/react@^16.8.0 but none is installed. You must install peer dependencies yourself.

How to reproduce the issue:

yarn init
yarn add react react-dom apollo-boost @apollo/react-hooks graphql

Version

System:
    OS: macOS 10.14.5
  Binaries:
    Node: 10.14.2 - ~/.nvm/versions/node/v10.14.2/bin/node
    Yarn: 1.17.3 - /usr/local/bin/yarn
    npm: 6.4.1 - ~/.nvm/versions/node/v10.14.2/bin/npm
  Browsers:
    Chrome: 76.0.3809.100
    Firefox: 68.0.2
    Safari: 12.1.1
  npmPackages:
    apollo-boost: ^0.4.4 => 0.4.4

Most helpful comment

To simplify things, do I need to install these for things to work or not. That's all I need to know.

All 14 comments

Experiencing the same. I'm using yarn.

Respectfully, I would classify this as desired behavior. Open source packages commonly specify peer dependencies and yarn/npm is being helpful with these warning messages e.g. doing a yarn add react-dom would result in a warning " > [email protected]" has unmet peer dependency "react@^16.0.0". You are experiencing similar behavior here where the @apollo/react-hooks package in the monorepo specifies its own peer dependencies. Older version on yarn/npm used to automatically install peer deps but that caused complications which is why the community has moved away from it.

I see your point @hansjhoffman though I would argue the documentation of React states that you have to install react alongside react-dom. It's not the case for Apollo's doc.

That put aside, it's strange that yarn and npm does not results in the same missing peer deps (though it's more their problem than Apollo's).

As mentioned in https://github.com/apollographql/react-apollo/issues/3394#issuecomment-524127174, this is desired behavior. This is all going to change very soon when React Apollo is merged into the Apollo Client project. Thanks!

So the idea for now is for me to add every peer deps to my project, ie "@types/react@^16.8.0", "apollo-client@^2.6.4" and "apollo-utilities@^1.3.2". Correct @hwillson ?

Thing is yarn complains even when the required peer dependencies are already installed if the version is mismatching.

for example in my project I'm using react@latest(16.10.2) and the following shows in yarn:
warning " > @apollo/[email protected]" has unmet peer dependency "react@^16.8.0".

Is this desired behavior?

For me, I'm getting warnings about typescript peer dependencies, which I'm not using:

npm WARN @apollo/[email protected] requires a peer of @types/react@^16.8.0 but none is installed. You must install peer dependencies yourself.
npm WARN @apollo/[email protected] requires a peer of @types/react@^16.8.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta but none is installed. You must install peer dependencies yourself.

So @apollo/react-common and @apollo/react-hooks list @types/react as a peerDependency. I think the warning about tsutils seems to come from another package, unrelated to apollo.

As mentioned in #3394 (comment), this is desired behavior. This is all going to change very soon when React Apollo is merged into the Apollo Client project. Thanks!

What is the timing of this "very soon"...?

To simplify things, do I need to install these for things to work or not. That's all I need to know.

npm root -g
go to global packages
open package.json
find the "peerDependencies" and add ^ on respective npm pckg
and you are done

or simply cleaning global node_modules dir (in case you don't need global packages any longer) also helped

To simplify things, do I need to install these for things to work or not. That's all I need to know.

@hwillson

To simplify things, do I need to install these for things to work or not. That's all I need to know.

@hwillson
That's what i really want to know

The answer is a bit complicated (which is why we're super excited to finally merge parts of this project into Apollo Client). The most important peer dep to have is apollo-client, but if you're using apollo-boost for example, you should already have it as a transitive dependency (so you can ignore that warning). @types/react is only needed if you're using Typescript, and it's listed as a peer dep because of the issue outlined in https://github.com/apollographql/react-apollo/pull/3278.

If you're just using React Apollo's hooks, I suggest trying out the Apollo Client 3 beta (@apollo/client@beta) which doesn't have any of these issues.

Was this page helpful?
0 / 5 - 0 ratings