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.

[Bug]: TypeError: React.createContext is not a function

See original GitHub issue

What package within Headless UI are you using?

@headlessui/react

What version of that package are you using?

1.2.0

What browser are you using?

N/A

Reproduction repository

https://github.com/rgbrizzlehizzle/ba-sing-se

Describe your issue

I am experiencing the same issue raised in https://github.com/tailwindlabs/tailwindui-react/issues/5 😞

I’m a total front-end scrub so apologies if this turns out to be something that is completely my fault lol.

It also seems possible that this is a problem with Jest, but it seemed to make sense to open it up here first since someone else also had the same issue.

Issue can be replicated by cloning the repo that I linked and running yarn test

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10

github_iconTop GitHub Comments

13reactions
venablescommented, Jun 30, 2021

For those encountering this issue, it is likely due to including . in the moduleDirectories section of jest.config.js like so:

moduleDirectories: ['node_modules', '.'],

Either removing the . or changing it to <rootDir> solved the issue:

moduleDirectories: ['node_modules', '<rootDir>'],

A similar issue + solution was reported with theme-ui.

5reactions
haghighi251commented, Nov 17, 2022

Hi, If you are using Next.js 13 you have to add ‘use client’; to your component. Please for more information check the link below: https://beta.nextjs.org/docs/rendering/server-and-client-components Otherwise, check if you have installed the latest version of react and react-dom.

Read more comments on GitHub >

github_iconTop Results From Across the Web

"React.createContext is not a function" - but I am not using it
createContext is not a function " error while running a react-native application. I searched for 'createContent' in the code, it doesn't exist.
Read more >
Uncaught TypeError: _react.default.createContext is not a ...
I'm getting this error and the app won't render: Uncaught TypeError: _react.default.createContext is not a function at Object.
Read more >
The child node of a React context consumer ... - DeepScan
REACT_BAD_CONTEXT_CONSUMER_CHILD; Error; High; react. This rule applies when the child ... (TypeError: render is not a function) <Context.
Read more >
[Solved]-"React.createContext is not a function" - appsloveworld
In your package react and react-dom are not having the same version which is why you get the error. react-dom@16.4.0 will want to...
Read more >
uncaught typeerror: (0 , react__ ...
The reason you are getting this error is because one of your dependencies (or maybe even your code) relies on React.createContext method. 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