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

"error createContext only works in Client Components" still exists #60877

Open
sheetalsindhu opened this issue Jan 19, 2024 · 6 comments
Open
Labels
Documentation Related to Next.js' official documentation.

Comments

@sheetalsindhu
Copy link

What is the improvement or update you wish to see?

I am getting this error in my project, after updating each and every file with "use client" still exists

  • error 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
    at eval (webpack-internal:///(rsc)/./node_modules/next/dist/shared/lib/router-context.js:13:38)
    at (rsc)/./node_modules/next/dist/shared/lib/router-context.js (/Users/sheetalsindhu/Desktop/code/raftel/.next/server/app/page.js:2356:1)
    at webpack_require (/Users/sheetalsindhu/Desktop/code/raftel/.next/server/webpack-runtime.js:33:43)
    at eval (webpack-internal:///(rsc)/./node_modules/next/dist/client/router.js:36:24)
    at (rsc)/./node_modules/next/dist/client/router.js (/Users/sheetalsindhu/Desktop/code/raftel/.next/server/app/page.js:2004:1)
    at webpack_require (/Users/sheetalsindhu/Desktop/code/raftel/.next/server/webpack-runtime.js:33:43)
    at eval (webpack-internal:///(rsc)/./node_modules/next/router.js:2:18)
    at (rsc)/./node_modules/next/router.js (/Users/sheetalsindhu/Desktop/code/raftel/.next/server/app/page.js:2741:1)
    at webpack_require (/Users/sheetalsindhu/Desktop/code/raftel/.next/server/webpack-runtime.js:33:43)
    at eval (webpack-internal:///(rsc)/./node_modules/next-redux-wrapper/lib/index.js:177:16) {
    name: 'TypeError',
    digest: undefined
    }

Is there any context that might help us understand?

"next": "13.4.13",
"react": "^18.2.0",

Does the docs page already exist? Please link to it.

https://nextjs.org/docs/messages/context-in-server-component

@sheetalsindhu sheetalsindhu added the Documentation Related to Next.js' official documentation. label Jan 19, 2024
@sheetalsindhu sheetalsindhu changed the title Docs: Docs: createContext only works in Client Components. Jan 19, 2024
@sheetalsindhu sheetalsindhu changed the title Docs: createContext only works in Client Components. "error createContext only works in Client Components" still exists Jan 19, 2024
@delbaoliveira
Copy link
Contributor

Hey @sheetalsindhu, could you please delete your .next directory? Wondering if it's a bad cache.

@bonface221
Copy link

@sheetalsindhu add "use client" on the component with the create context only.

Then wrap the component in your layout or where you intend to use it

e.g this is a client auth provider
image

wrapped over other components

image

@ryozm
Copy link

ryozm commented Jan 26, 2024

I got same error when i use @next/mdx, If this error occurs when you also use mdx, ensure mdx-components.tsx is at the root of your project
#47523 #47523 (comment)

@asd58584388
Copy link

I got the same error, after moving mdx-components.tsx to the root of my project, I solved it.

@cleytonoliveira
Copy link

I got the same error trying to migrate from Pages to App. I put the 'use client' at the beginning of my Context, but it doesn't work.

@wenzhen-gong
Copy link

I got the same error trying to migrate from Pages to App. I put the 'use client' at the beginning of my Context, but it doesn't work.

Same here. @emotion/styled works perfectly in Pages but not the case in App

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Related to Next.js' official documentation.
Projects
None yet
Development

No branches or pull requests

7 participants