Sandip Guchait
Sandip Guchait

Reputation: 159

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'));

Upvotes: 1

Views: 1394

Answers (2)

user2958194
user2958194

Reputation: 116

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

Upvotes: 1

kiran bhalerao
kiran bhalerao

Reputation: 11

Go to node_modules/react-scripts/config/webpack.config (both dev && prod files)

{
  test: /\.mjs$/,
  include: /node_modules/,
  type: "javascript/auto"
},

past the above code inside rules: [

Upvotes: 1

Related Questions