[英]new ApolloClient() results in WebPack error?
Im trying to get a basic React / Apollo app set up. 我试图建立一个基本的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;
But it appears this line: 但似乎出现以下行:
const client = new ApolloClient();
Results in an error: 导致错误:
TypeError: __WEBPACK_IMPORTED_MODULE_1_react_apollo__.ApolloClient is not a constructor
If you are using v2, there's a lot of changes from v1, see apollo docs 如果您使用的是v2,则与v1相比有很多变化,请参阅apollo文档
You have to import from apollo-client now : 您现在必须从apollo-client导入:
import { ApolloClient } from 'apollo-client';
But the provider is still from react-apollo : 但是提供者仍然来自react-apollo:
import { ApolloProvider } from 'react-apollo';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.