`app` dir does not work with React.createContext
See original GitHub issueVerify canary release
- I verified that the issue exists in the latest Next.js canary release
Provide environment information
Operating System:
Platform: linux
Arch: x64
Version: #137-Ubuntu SMP Wed Jun 15 13:33:07 UTC 2022
Binaries:
Node: 16.18.0
npm: 8.3.0
Yarn: 1.22.18
pnpm: 6.32.11
Relevant packages:
next: 13.0.0
eslint-config-next: 13.0.0
react: 18.2.0
react-dom: 18.2.0
What browser are you using? (if relevant)
N/A, but Node.js is v16.18.0
How are you deploying your application? (if relevant)
next dev
Describe the Bug
Using @emotion/react
as jsxImportSource
does not work with app
dir, with the following error:
Server Error
TypeError: React.createContext is not a function
This error happened while generating the page. Any console logs will be displayed in the terminal window.
Call Stack
eval
(sc_server)/node_modules/@emotion/react/dist/emotion-element-b63ca7c6.cjs.dev.js (21:47)
Object.(sc_server)/./node_modules/@emotion/react/dist/emotion-element-b63ca7c6.cjs.dev.js
file:///home/me/app/.next/server/app/page.js (425:1)
console.log(React)
at the error site shows that it indeed doesn’t have createContext
.
React.version
is 18.3.0-next-d925a8d0b-20221024
.
Expected Behavior
Using @emotion/react
as jsxImportSource
works with app
dir.
Link to reproduction
https://replit.com/@alex-kinokon/app-playground
To Reproduce
Set jsxImportSource
to @emotion/react
in tsconfig.json
Issue Analytics
- State:
- Created a year ago
- Reactions:8
- Comments:11 (1 by maintainers)
Top Results From Across the Web
`react-query` hydration in /app/page.tsx thrown error ... - GitHub
I can open a new issue with them and see if they're willing to add it even though appDir is still experimental and...
Read more >React createContext/useContext does not survive between ...
The problem is that you used a regular <a> link to navigate through the app and every time you go from Home to...
Read more >React Context API: What is it and How it works?
Context API is a (kind of) new feature added in version 16.3 of React that allows one to share state across the entire...
Read more >3 Things Every React Context Should Have | DevLog 008
In this case, one thing to note is that the AppComponent won't work on its own if you use it within the same...
Read more >How To Build An App With React Context API
createContext is a React context API for creating contexts, it is a function that takes a default value as its only argument. This...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi, this is expected if the component using
createContext
isn’t marked withuse client
. We are already working on a better error message and adding it to the docs soon to explain this better, but the behavior here is not a bug, so I am closing this. Thanks for reporting!This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.