Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 777
Davit Gelovani Avatar asked Jan 19 '26 04:01

Davit Gelovani


2 Answers

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 🚀

like image 97
erwan Avatar answered Jan 20 '26 19:01

erwan


Solution for me:

import { default as pkg } from '@apollo/client'
const { ApolloClient, ApolloProvider, InMemoryCache, createHttpLink } = pkg
like image 31
Israel Saraiva Avatar answered Jan 20 '26 17:01

Israel Saraiva



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!