所以我收到了这个奇怪的错误,ReferenceError:require在从"apollo-boost"导入ApolloClient时没有定义。不导入ApolloClient应用程序正在运行,但导入时显示错误。错误的屏幕截图在所附的图像中:这是图像
这是我的密码
index.js
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'));
安装graphql v14.0.2(或新版本(。Graphql包必须在您的package.json.中
有关更多信息,请参阅此处的原始解决方案:https://github.com/apollographql/apollo-link-state/issues/299#issuecomment-421784547
转到node_modules/react-scripts/config/webpack.config(包括开发和生产文件(
{
test: /.mjs$/,
include: /node_modules/,
type: "javascript/auto"
},
在rules: [
内通过上述代码