javascriptgraphqlapollo-client

SyntaxError: Named export 'ApolloClient' not found


I'm trying to create server with ApolloClient and GraphQL but got the following error:

SyntaxError: Named export 'ApolloClient' not found. The requested module '@apollo/client' is a CommonJS module, which may not support all module.exports as named exports.

my code looks like this:

import { ApolloClient, InMemoryCache, createHttpLink } from '@apollo/client'

const httpLink = createHttpLink({
  uri: 'http://localhost:4000/graphql',
})

const createApolloClient = () => {
  return new ApolloClient({
    link: httpLink,
    cache: new InMemoryCache(),
  })
}

export default createApolloClient

I tried

import pkg from '@apollo/client'
const { ApolloClient, InMemoryCache, createHttpLink } = pkg

but it didn't help


Solution

  • Good news @davit-gelovani

    I reached to import Apollo the way you need, just like that :

    import { ApolloClient, InMemoryCache } from "@apollo/client/core/core.cjs";
    import { HttpLink } from "@apollo/client/link/http/http.cjs";
    

    on @apollo/client version 3.7.0 🚀