Search code examples
reactjsgraphqlreact-apollographql-jsapollo-client

ReferenceError: require is not defined when importing ApolloClient from 'apollo-boost'


So I am getting this strange error, ReferenceError: require is not defined when importing ApolloClient from 'apollo-boost'. Without importing ApolloClient app is running but when importing it shows error. Screenshot of the error is in the image attached: Here is the image

Here is my Code

index.js

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './components/App';

import  ApolloClient  from 'apollo-boost';
import { ApolloProvider } from 'react-apollo';


const client = new ApolloClient({
    uri:"http://localhost:4444/graphql"
})
ReactDOM.render(
    <ApolloProvider client={client}>
        <App />
    </ApolloProvider>
, document.getElementById('root'));

Solution

  • Install graphql v14.0.2 (or new one). Graphql package must be in your package.json.

    For more see original solution here: https://github.com/apollographql/apollo-link-state/issues/299#issuecomment-421784547