新的ApolloClient()导致WebPack错误?

时间:2017-12-11 08:41:03

标签: reactjs apollo

我试图设置一个基本的React / Apollo应用程序。

import React, { Component } from 'react';
import { ApolloClient, ApolloProvider } from 'react-apollo';
import './App.css';
import Contacts from './Contacts';

const client = new ApolloClient();

class App extends Component {
  render() {
    return (
      <ApolloProvider client={client}>
        <div className="App">
          <header className="App-header">
            <h1 className="App-title">Welcome to React</h1>
          </header>
          <Contacts />
        </div>
      </ApolloProvider>
    );
  }
}

export default App;

但看起来这一行:

const client = new ApolloClient();

导致错误:

TypeError: __WEBPACK_IMPORTED_MODULE_1_react_apollo__.ApolloClient is not a constructor

enter image description here

1 个答案:

答案 0 :(得分:0)

如果您使用的是v2,那么v1会有很多变化,请参阅apollo docs

您现在必须从apollo-client导入:

import { ApolloClient } from 'apollo-client';

但提供者仍然来自react-apollo:

import { ApolloProvider } from 'react-apollo';