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

Using next-yak converts server components to client components #112

Open
inuwan opened this issue Jul 8, 2024 · 9 comments
Open

Using next-yak converts server components to client components #112

inuwan opened this issue Jul 8, 2024 · 9 comments
Labels
bug Something isn't working

Comments

@inuwan
Copy link

inuwan commented Jul 8, 2024

Using a next-yak styled component with a server component (page.tsx) that defines the Next.js special function generateMetadata. I get the following error:

You are attempting to export "generateMetadata" from a component marked with "use client", which is disallowed. Either remove the export, or the "use client" directive. Read more: https:// │ nextjs.org/docs/getting-started/react-essentials#the-use-client-directive

If I remove the next-yak styled component, the error is eliminated.

@jantimon
Copy link
Owner

jantimon commented Jul 9, 2024

hi @inuwan

thanks for reporting the issue

could you please set up a minimal reproduction example?

@jantimon jantimon added the bug Something isn't working label Jul 9, 2024
@jantimon
Copy link
Owner

jantimon commented Jul 9, 2024

it looks like there is a bug in next.js and or css-loader but I am still investigating it

the error NextRscErrClientMetadataExport is thrown by some rust code which shouldn't mess with the css at all 🤷‍♂️

https://github.com/vercel/next.js/blob/8f93430080f1c18b3f25a0b9c842063f6dc9c9e8/packages/next-swc/crates/next-custom-transforms/src/transforms/react_server_components.rs#L738-L749

error definition:

https://github.com/vercel/next.js/blob/8f93430080f1c18b3f25a0b9c842063f6dc9c9e8/packages/next-swc/crates/next-custom-transforms/src/transforms/react_server_components.rs#L281-L283

@jantimon
Copy link
Owner

jantimon commented Jul 9, 2024

Created a reproduction example here:

https://github.com/jantimon/reproduction-next-server-component-css-error

@jantimon
Copy link
Owner

jantimon commented Jul 9, 2024

Reported at next.js: vercel/next.js#67591

@jantimon
Copy link
Owner

jantimon commented Jul 9, 2024

As a intermediate solution you could split the code - everything works as long as metadata and yak styled components are not used within the same file

@Mad-Kat
Copy link
Collaborator

Mad-Kat commented Jul 9, 2024

I think we should create another example with this case in our repo. What do you think @jantimon ?

@jantimon
Copy link
Owner

@Mad-Kat - yes we should definitely improve our examples (a more realistic one and a very basic one) 👍

Btw I found the reason for this bug.

During processing Next.js identifies import __styleYak from "./page.yak.module.css!=!./page?./page.yak.module.css as a page and therefore creates an entry out of it:

vercel/next.js#67591 (comment)

@laem
Copy link

laem commented Nov 28, 2024

As a intermediate solution you could split the code - everything works as long as metadata and yak styled components are not used within the same file

I tried this, it worked at first. But the navigating on the page triggered the error again...

@jantimon
Copy link
Owner

jantimon commented Nov 28, 2024

There is an open bug in next.js but I believe nobody is working on it

vercel/next.js#67591

can you please show us how you are splitting it?
maybe we can help you to fix it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants