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.

TypeError: (0 , import_react14.createContext) is not a function (Next.js 13)

See original GitHub issue

What package within Headless UI are you using?

@headlessui/react

What version of that package are you using?

v1.7.4

What browser are you using?

Chrome Version 107.0.5304.88 (64-bit)

Reproduction URL

https://github.com/colecline22/test-next https://codesandbox.io/p/github/colecline22/test-next/headless-error

Describe your issue HeadlessUI components are not working in Next.js 13 due to createContext.

error - (sc_server)/node_modules/@headlessui/react/dist/headlessui.dev.cjs (810:48) @ eval
error - TypeError: (0 , import_react14.createContext) is not a function
    at eval (webpack-internal:///(sc_server)/./node_modules/@headlessui/react/dist/headlessui.dev.cjs:801:48)
    at Object.(sc_server)/./node_modules/@headlessui/react/dist/headlessui.dev.cjs (/project/test-next/.next/server/app/page.js:1076:1)
    at __webpack_require__ (/project/test-next/.next/server/webpack-runtime.js:33:42)
    at eval (webpack-internal:///(sc_server)/./src/components/Button.jsx:6:75)
    at Object.(sc_server)/./src/components/Button.jsx (/project/test-next/.next/server/app/page.js:405:1)
    at __webpack_require__ (/project/test-next/.next/server/webpack-runtime.js:33:42)
    at eval (webpack-internal:///(sc_server)/./src/app/page.jsx:6:76)
    at Object.(sc_server)/./src/app/page.jsx (/project/test-next/.next/server/app/page.js:394:1)
    at __webpack_require__ (/project/test-next/.next/server/webpack-runtime.js:33:42)
    at Object.page (webpack-internal:///(sc_server)/./node_modules/next/dist/build/webpack/loaders/next-app-loader.js?name=app%2Fpage&appPaths=%2Fpage&pagePath=private-next-app-dir%2Fpage.jsx&appDir=%2Fproject%2Ftest-next%2Fsrc%2Fapp&pageExtensions=tsx&pageExtensions=ts&pageExtensions=jsx&pageExtensions=js&rootDir=%2Fproject%2Ftest-next&isDev=true&tsconfigPath=tsconfig.json!:19:96) {
  type: 'TypeError',
  page: '/'
}

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

1reaction
KjellConnellycommented, Nov 8, 2022

Hopefully they’ll add a way to call a component a client component without having to add "use client" to the top of every file and wrapping it. Fortunately, Next13 is not stable yet, so expect some better solution than wrapping every UI component with this. (Btw, you could just add this to every file you use a client component in (everything with hooks like useState), but in order to get server components, you want to only "use client" as minimally as possible. Which is why I hope they make it easier very soon.

1reaction
RobinMalfaitcommented, Nov 8, 2022

This is a Next.js/React “issue” (by design) but the development experience is not ideal.

The problem is that createContext, useEffect and friends don’t work in server components which is the default for the new app directory.

You can solve this by using the "use client" directive in the file you use Headless UI components in so that they are client components and not server components.

Don’t be confused by the name, because SSR still works.

More info: https://beta.nextjs.org/docs/rendering/server-and-client-components#convention

Read more comments on GitHub >

github_iconTop Results From Across the Web

"TypeError: react.createContext" is not a function with Next.js ...
I'm using a Radix UI select component in Next.js 13 with Typescript and it throws this error: TypeError: $9g4ps$react.createContext is not a ......
Read more >
Using-inferno: React.createContext is not a function #9021
Expected behavior. I expect the app to work without errors. System information. Version of Next.js: latest. Additional context.
Read more >
Context API with TypeScript and Next.JS - DEV Community ‍ ‍
Step 1:- Create context type. Inside AuthContext.tsx. As we are using TypeScript we have to create types for our context. type authContextType ...
Read more >
Quick Tip: Sharing Data in Next.js with React Context
Learn the steps involved in setting up React Context and how to use it to store menu data in the Next.js WordPress Starter....
Read more >
Using React Context for state management in Next.js - Netlify
There are a lot of different ways to manage state in Next.js applications, ... import { createContext, useContext } from 'react';
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