0

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.

Daniel
  • 14,004
  • 16
  • 96
  • 156
  • Here's the [likely culprit](https://github.com/graphql/graphql-js/issues/1272). Based on [this](https://github.com/facebook/create-react-app/pull/4642) it's unclear whether this was finally addressed in CRA or not, but I see the `mjs` extension listed [here](https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/config/webpack.config.js). Maybe check and make sure you're using the latest version of CRA? – Daniel Rearden Jan 21 '19 at 09:36
  • @DanielRearden, this is the version of CRA I have: https://github.com/facebook/create-react-app/blob/master/CHANGELOG.md. Could it be I need to use an older version? – Daniel Jan 21 '19 at 13:44
  • I changed the version of CRA, but I am still getting the same error. – Daniel Jan 21 '19 at 14:02

1 Answers1

0

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.

Daniel
  • 14,004
  • 16
  • 96
  • 156