apollo-client: [3.0.0-beta.24] Module not found: Can't resolve 'apollo-client' in 'node_modules/@apollo/react-hooks/lib'

Upgraded to 3.0.0-beta, everything worked until I did a hard restart of my create-react-app. Upon running my app, I receive the following error:

./node_modules/@apollo/react-hooks/lib/react-hooks.esm.js
Module not found: Can't resolve 'apollo-client' in '/Users/bstrom/dev/reviewtool/node_modules/@apollo/react-hooks/lib'

Versions System: OS: macOS Mojave 10.14.6 Binaries: Node: 12.13.0 - ~/.nvm/versions/node/v12.13.0/bin/node Yarn: 1.21.1 - /usr/local/bin/yarn npm: 6.12.0 - ~/.nvm/versions/node/v12.13.0/bin/npm Browsers: Chrome: 79.0.3945.117 Firefox: 72.0.1 Safari: 13.0.4 npmPackages: @apollo/client: ^3.0.0-beta.24 => 3.0.0-beta.24 @apollo/react-hooks: ^3.1.3 => 3.1.3 @apollo/react-testing: ^3.1.3 => 3.1.3 apollo-cache-inmemory: ^1.6.5 => 1.6.5 apollo-link: ^1.2.13 => 1.2.13 apollo-link-error: ^1.1.12 => 1.1.12 apollo-link-http: ^1.5.16 => 1.5.16 apollo-server: ^2.9.7 => 2.9.15 –>

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 17 (3 by maintainers)

Most upvoted comments

@bstro we haven’t quite finished our migration guide yet (it should be done this upcoming week), but React Apollo’s hooks are now included in @apollo/client. You can (and should) drop your @apollo/react-hooks dependency, and instead import directly from @apollo/client.

Thank you @mhuconcern ! Based on what you said, I looked into it further and realized there was a beta version of react-ssr ( “@apollo/react-ssr”: “^4.0.0-beta.1”), and that fixed it upon updating. Seems like the old ssr had the hooks dependency, and that was my problem!

@mshahbazm because @latest is stable. you need to use @beta

npm install @apollo/react-components@beta

You can always check what versions are available on the Versions Tab on npm: https://www.npmjs.com/package/@apollo/react-components?activeTab=versions

@TheoMer Are you using next-with-apollo? I was facing this issue today. You’ll need to install the latest 5.0 version. Because some of my code is still not refactored to hooks I also needed to use @apollo/react-components@beta. Also if you want to use SSR you need to install @apollo/react-ssr@beta and then import getDataFromTree and pass it:

import withApollo from 'next-with-apollo';
import { getDataFromTree } from '@apollo/react-ssr';
import { notification } from 'antd';
import {
  ApolloClient,
  ApolloLink,
  HttpLink,
  InMemoryCache,
} from '@apollo/client';
import { onError } from '@apollo/link-error';

export default withApollo(
  ({ ctx, headers, initialState }) =>
    new ApolloClient({
      link: ApolloLink.from([
        onError(({ graphQLErrors, networkError, response }) => {
          if (graphQLErrors) {
            // Do something with the errors
            graphQLErrors.forEach(error => {
              // console.log(error);
              console.error(
                `[GraphQL error]: Message: ${error.message}, Location: ${error.locations}, Path: ${error.path}`
              );
              notification.error({
                message: 'Error',
                description: error.message,
              });
            });
          } else if (networkError) {
            console.error(`[Network error]: ${networkError}`);
          }
        }),
        new HttpLink({
          uri: process.env.NODE_ENV === 'development' ? endpoint : backendUrl,
          credentials: 'include',
          headers: {
            cookie: headers && headers.cookie,
          },
        }),
      ]),
      cache: new InMemoryCache({}).restore(initialState || {}),
    }),
  { getDataFromTree }
);

This solves my issue but I noticed you added this to your release milestone so I’ll leave this open. Thank you for getting back to me so quickly.