apollographql / apollo-client-nextjs

Apollo Client support for the Next.js App Router
https://www.npmjs.com/package/@apollo/experimental-nextjs-app-support
MIT License
358 stars 25 forks source link

RSC getClient() not working with Next 14 #179

Closed ninibear030 closed 2 months ago

ninibear030 commented 3 months ago

i am using next 14.0.4 "@apollo/client": "3.9.0-rc.1", "@apollo/experimental-nextjs-app-support": "^0.6.0", tutorial link: https://www.apollographql.com/blog/using-apollo-client-with-next-js-13-releasing-an-official-library-to-support-the-app-router

when I use it in my RSC i get error:

'server-only' cannot be imported from a Client Component module. It should only be used from a Server Component.
The error was caused by importing '@apollo/experimental-nextjs-app-support/dist/rsc/index.js' in '../../...'.
phryneas commented 3 months ago

That error message states that you are importing Server Component functionality in a Client Component. Are you sure that the file you are importing into is not used as a Client Component?

This doesn't have to be a file with "use client", it can also be a file imported by a file that has "use client", or even imported by a file that is imported by a file etc.

ninibear030 commented 3 months ago

I used that in the page.tsx, I don't think its possible for it to be client side. 😞😭

phryneas commented 3 months ago

page.tsx can also be a client component. Unfortunately I fear I can't really help you with this without knowing your full project.

I think it might actually better if you asked in the Next.js Discord - from the error message you shared, it seems like this is not a bug in this package.

phryneas commented 2 months ago

I'm doing some housekeeping so I'm closing some older issues that haven't seen activity in a while. If this is still relevant, please feel free to reopen the issue.

github-actions[bot] commented 2 months ago

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.

gersongams commented 2 months ago

I'm having the same issue 😢

phryneas commented 2 months ago

@gersongams that means that you are importing a file that contains registerApolloClient from a Client component. That could also happen over a few corners - you import a file from a "use client" file that imports a file that imports a file that imports registerApolloClient.

That's not allowed in Next.js - things meant for the server have to stay on the "server side" of imports and things meant for the client have to stay on the "client side" of imports.