Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to import in Next 15 due to registerApolloClient #383

Open
oalexdoda opened this issue Oct 27, 2024 · 4 comments
Open

Unable to import in Next 15 due to registerApolloClient #383

oalexdoda opened this issue Oct 27, 2024 · 4 comments

Comments

@oalexdoda
Copy link

Hi,

It looks like @apollo/experimental-nextjs-app-support is throwing an error where it can't find registerApolloClient.

Not sure if it's because of it importing from index.ssr.js vs. another file, or what I'm doing wrong.

Would appreciate some help!

Thanks!

Code:

image

Server Error:

image

@phryneas
Copy link
Member

phryneas commented Oct 28, 2024

You should only get that if you try to import registerApolloClient from a Client Component, and it seems that this happens in a SSR step, which would indicate a Client Component.

I see that you do a server-only import at the top of the file, which should prevent that, but could you please double-check your import paths? Does any client component directly or indirectly import this? (Look out for barrel files!)

@oalexdoda
Copy link
Author

I had to pass the use server directive in that file for the import to work and it no longer crashes.

image

but it does cause a type error here

image

it builds/works in dev, but not sure if that's how it's supposed to be.

here's the index.ts that exports things (this is all in a transpiled next.js package)

image

and how it gets exported in the package.json

image

not sure if any of this helps, but trying to give you some context of how it's used

@phryneas
Copy link
Member

Yeah, you definitely shouldn't use the "use server", it turns everything there into server functions, not server components.

I assume that your index.ts here is the problem - if you import anything from a barrel file like that into a "use client" file, that turns everything there into "client side" code, which will then crash, even if it was only meant for the server and never for the client.

I'm afraid, but with RSC/Next.js you can't use barrel files like that - you either have to create a index.rsc.js and index.cc.js (or similar), or - probably even better for your bundle size - stop using barrel files altogether.

@oalexdoda
Copy link
Author

Got it, that makes perfect sense - thanks a lot @phryneas !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants