Closed Whitebytes closed 3 weeks ago
This should not have anything to do with TypeScript or not TypeScript.
You will get this error message if you import registerApolloClient
from a "use client"
file or a file that is imported from a "use client"
and so on. (It oftentimes happens if you have index.js
barrel files that just mix up Client and Server exports).
registerApolloClient
is only exported in a React Server Component context, just like useState
is only exported from react
in a "use client"
context, but not in a RSC context.
ok, can confirm this was the issue, thanx. Nature of the error gave me not any clue this was a ssr issue.. (like the one you get when using useState while ssr)..
Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Client usage and allow us to serve you better.
@phryneas I'm having the same issue when using the RSC client from the middleware. Not sure whether that's a bug in the library and this RSC client is not compatible with the middleware's context?
I think i got my answer there: https://github.com/apollographql/apollo-client-nextjs/issues/280#issuecomment-2059443275 So the client doesn't seem to have middleware support
Yeah, middleware are yet another layer of Next.js that lives outside of the React world. Just create a new ApolloClient instance inside of your middleware - there's no extra support or orchestration needed from our side.
(If we find a way of making this nicer, we'll look into that, but no guarantees when that can happen)
to reproduce:
npx create-next-app@latest What is your project named? ... my-app √ Would you like to use TypeScript? ... No √ Would you like to use ESLint? ... No √ Would you like to use Tailwind CSS? ... No √ Would you like to use
src/
directory? ... Yes √ Would you like to use App Router? (recommended) ... Yes ? Would you like to customize the default import alias (@/*)? » Nonpm install @apollo/client@latest @apollo/experimental-nextjs-app-support graphql
Seems to me incompatability when using nextjs without typescript. When installing Nextjs with typescript, the error dont exist.