apollographql / react-apollo

:recycle: React integration for Apollo Client
https://www.apollographql.com/docs/react/
MIT License
6.84k stars 786 forks source link

@apollo/react-hooks tried to access apollo-client #3897

Open jimhill opened 4 years ago

jimhill commented 4 years ago

Intended outcome:

A CRA application should compile and run

Actual outcome:

Failed to compile.

/my-path/.yarn/$$virtual/@apollo-react-hooks-virtual-b95e1268e6/0/cache/@apollo-react-hooks-npm-3.1.3-c8e01682c1-2.zip/node_modules/@apollo/react-hooks/lib/react-hooks.esm.js

Module not found: @apollo/react-hooks tried to access apollo-client (a peer dependency) but it isn't provided by its ancestors; this makes the require call ambiguous and unsound.

How to reproduce the issue:

This is using Yarn 2.0.0 berry and in my package.json having the following dependencies:

"dependencies": {
    "@apollo/client": "^3.0.0-beta.41",
    "@apollo/link-error": "^2.0.0-beta.3",
    ...
    "apollo-client": "^2.6.8",
}

Version

System:
    OS: macOS 10.15.3
  Binaries:
    Node: 13.11.0 - /usr/local/bin/node
    Yarn: 2.0.0-rc.30.git.20200322.3bbc8e17 - /usr/local/bin/yarn
    npm: 6.13.7 - /usr/local/bin/npm
  Browsers:
    Chrome: 80.0.3987.149
    Firefox: 68.0.1
    Safari: 13.0.5
kalzoo commented 4 years ago

Similar situation - the build artifact react-hooks.cjs.js includes the line:

var _apolloClient = require("apollo-client");

Correcting that to read

var _apolloClient = require("@apollo/client");

as a patch fix unblocks the build in the meantime.

My project package.json does not include apollo-client, only @apollo/client.

joonhocho commented 4 years ago

I am having the same issue. It seems versions are out of sync?

smeijer commented 4 years ago

I had the same issue. In my case it was caused by @apollo/react-hoc. Turned out I had @apollo/react-hoc@3.1.5 installed, upgrading it to the latest beta (@apollo/react-hoc@4.0.0-beta.1), fixed the issue.