question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`app` dir does not work with React.createContext

See original GitHub issue

Verify 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:closed
  • Created a year ago
  • Reactions:8
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
balazsorban44commented, Oct 27, 2022

Hi, this is expected if the component using createContext isn’t marked with use 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!

0reactions
github-actions[bot]commented, Nov 27, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found