Importing @apollo/client in CodeSandbox, getting TypeError Cannot read properties of undefined (reading 'FIELD')

Viewed 1019

Basically as the title says, I'm creating a React app in CodeSandbox and installing Apollo/Client as a dependency to link to my back end GraphQl. After I add it as a dependency, I try and import it to my index.js, but I get a "Type Error Cannot Read properties of undefined( reading 'field'). The error goes away when I remove the import.

import React from 'react';
import { render } from 'react-dom';
import {
  ApolloClient,
  InMemoryCache,
  ApolloProvider,
  useQuery,
  gql
} from "@apollo/client";

const client = new ApolloClient({
  uri: 'https://48p1r2roz4.sse.codesandbox.io',
  cache: new InMemoryCache()
});

function App() {
  return (
    <div>
      <h2>My first Apollo app </h2>
    </div>
  );
}

render(
  <ApolloProvider client={client}>
    <App />
  </ApolloProvider>,
  document.getElementById('root'),
);
1 Answers

Don't know if this is too late for you, but I was having the same issue. I fixed it by changing the version of my dependencies of Grapghql and @Apollo/Client.

graphql - 15.8.0 Apollo-client - 3.3.19

I am sure there is a better way to fix this, but this is what I found that worked hope it helps!

Related