React-apollo: ApolloClient is not a constructor

Created on 14 Nov 2017  ·  4Comments  ·  Source: apollographql/react-apollo

Intended outcome:
Be able to instantiate new ApolloClient() after running 'npm install react-apollo --save'. After running the npm install, following the README instructions, the only changes that were made included the adding of the import and trying to call new ApolloClient in my app.jsx.

import React, { Component } from 'react';
import { ApolloClient } from 'react-apollo';
import AdminFlow from './components/AdminFlow';
import ClientFlow from './components/ClientFlow';

import './assets/Fonts/font.scss';
import '../styles/index.scss';

const client = new ApolloClient();

class App extends Component {...}

Actual outcome:
ApolloClient does not appear to be included in the package. We dove into the node module and while we do see ApolloProvider there is no ApolloClient there.
image

Error is as follows after adding in those 2 lines of code:
image

How to reproduce the issue:
I took the sandbox, updated react-apollo to 2.0.1 and followed the README. Results in a different console error, but still it fails: https://codesandbox.io/s/7kjlxxrqy0

Version

"dependencies": {
    "apollo-client": "^2.0.2",
    "apollo-client-preset": "^1.0.2",
    "axios": "^0.16.2",
    "extract-text-webpack-plugin": "^3.0.1",
    "graphql": "^0.11.7",
    "html-webpack-plugin": "^2.30.1",
    "lodash": "^4.17.4",
    "moment": "^2.19.1",
    "node-sass": "^4.5.3",
    "react": "^16.0.0",
    "react-apollo": "^2.0.1",
    "react-dom": "^16.0.0",
    "react-hot-loader": "^3.0.0",
    "react-js-pagination": "^3.0.0",
    "react-json-pretty": "^1.7.4",
    "react-modal": "^3.1.2",
    "react-tabs": "^2.1.0",
    "webpack": "^3.7.1",
    "webpack-dashboard": "^1.0.0-5",
    "webpack-dev-server": "^2.9.1"
  },
  "devDependencies": {
    "babel-core": "^6.26.0",
    "babel-eslint": "^8.0.1",
    "babel-loader": "^7.1.2",
    "babel-plugin-transform-class-properties": "^6.24.1",
    "babel-plugin-transform-decorators-legacy": "^1.3.4",
    "babel-plugin-transform-runtime": "^6.23.0",
    "babel-polyfill": "^6.26.0",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-react": "^6.24.1",
    "babel-runtime": "^6.26.0",
    "css-loader": "^0.28.7",
    "eslint": "^4.8.0",
    "eslint-config-airbnb": "^16.0.0",
    "eslint-plugin-import": "^2.7.0",
    "eslint-plugin-jsx-a11y": "^6.0.2",
    "eslint-plugin-react": "^7.4.0",
    "file-loader": "^1.1.5",
    "resolve-url-loader": "^2.1.1",
    "sass-loader": "^6.0.6",
    "style-loader": "^0.19.0",
    "url-loader": "^0.6.2",
    "webpack-node-externals": "^1.6.0"
  }

Most helpful comment

Link to docs is dead

All 4 comments

Same here :(

Hi there! ApolloClient is no longer in react-apollo. You have to import it from 'apollo-client'. Check the migration guide for more details: https://www.apollographql.com/docs/react/2.0-migration.html#install

@peggyrayzis Thank you for the quick response as well as updating the README!

Link to docs is dead

Was this page helpful?
0 / 5 - 0 ratings