Search code examples
create-react-appreact-apolloapollo-boost

Node with GraphQL and React Require not defined


I am developing a Node with GraphQL backend and just started working on the front end with create-react-app.

It was going well until I added this code:

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

The Apollo code is what broke it to where it is telling me require is not defined. I understand the error to be concerning the utilization of require statements on the browser side which I am not.


Solution

  • I am getting this error because I did not install all the preset packages I was supposed to install apparently.

    I initially installed:

    npm install react-apollo apollo-boost jwt-decode

    When I should have installed:

    npm install react-apollo apollo-boost jwt-decode graphql-tag graphql --save

    Once I did so, the error went away. All I can say is that graphql-tag and graphql has some dependencies for apollo-boost and react-apollo I imagine.