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

TypeError: Emotion Causes Unexpected Client Component Requirement in Next.js 15.1.6 #3311

Open
nokia1054g opened this issue Feb 6, 2025 · 0 comments

Comments

@nokia1054g
Copy link

nokia1054g commented Feb 6, 2025

An issue arises when using Emotion with Next.js 15.1.6, where the application unexpectedly crashes in development mode (npm run dev) due to Emotion seemingly being invoked in server components, despite being used only within a client wrapper.

TypeError: createContext only works in Client Components. Add the "use client" directive at the top of the file to use it.
Read more: https://nextjs.org/docs/messages/context-in-server-component

The stack trace suggests that Emotion is causing the issue even in components where it is not directly imported.

Reproduction Steps

git clone: https://github.com/nokia1054g/EmotionNextBug
npm run dev

In open Words:

Create a Next.js 15.1.6 project with Emotion.

Use Emotion within a page.tsx client wrapper component.

Run npm run dev, and observe the application crash on refresh.

Marking everything as a client component resolves the error but disrupts server component usage.

Expected Behavior

Server components should not be affected by Emotion usage within a client wrapper.

The app should not require marking layout.tsx and page.tsx as client components.

Actual Behavior

The app crashes when running in dev mode, claiming that createContext must be used in client components.

The issue disappears when marking server components as client components, but this breaks the expected Next.js architecture.

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

No branches or pull requests

1 participant