ReferenceError: require is not defined when importing ApolloClient from 'apollo-boost'

ReferenceError: require is not defined when importing ApolloClient from 'apollo-boost'

所以我收到了这个奇怪的错误,ReferenceError: require is not defined 从 'apollo-boost' 导入 ApolloClient 时。不导入 ApolloClient 应用程序是 运行 但在导入时显示错误。 错误的屏幕截图在附件中: Here is the image

这是我的代码

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'));

转到node_modules/react-scripts/config/webpack.config(开发和生产文件)

{
  test: /\.mjs$/,
  include: /node_modules/,
  type: "javascript/auto"
},

rules: [

中输入上面的代码

安装 graphql v14.0.2(或新版本)。 Graphql 包必须在您的 package.json.

有关更多信息,请在此处查看原始解决方案:https://github.com/apollographql/apollo-link-state/issues/299#issuecomment-421784547