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

React 18 error: "./jsx-runtime.js is not exported from package" #164

Closed
dstroot opened this issue Mar 29, 2022 · 6 comments
Closed

React 18 error: "./jsx-runtime.js is not exported from package" #164

dstroot opened this issue Mar 29, 2022 · 6 comments

Comments

@dstroot
Copy link

dstroot commented Mar 29, 2022

  • mdx-bundler version: ^8.0.1
  • node version: 16.14.2
  • npm version: 8.5

Relevant code or config

  • N/A

What you did:

I upgraded to React 18 from 17.0.2

What happened:

NOTE: Also using Next.js version 12.1.2. When I run "build" after upgrading react from 17.0.2 to 18.0 I get the error below:


./node_modules/mdx-bundler/dist/client.js
Module not found: Package path ./jsx-runtime.js is not exported from package /Volumes/T7/Code/blog-next/node_modules/react (see exports field in /Volumes/T7/Code/blog-next/node_modules/react/package.json)

Import trace for requested module:
./node_modules/mdx-bundler/client/index.js
./pages/snippets/[slug].jsx


Reproduction repository:

Problem description:

React 18 seems to introduce a problem with how jsx-runtime is consumed from React. MDX-Bundler pull request #162 may address this issue already. I am not sure.

Suggested solution:

Maybe test React 18 with Pull Request 162?
Also see similar issue here: hashicorp/next-mdx-remote#250

@schickling
Copy link

schickling commented Mar 30, 2022

I was facing the same problem with Contentlayer and found a workaround/solution that works for Next.js:

image

@dstroot
Copy link
Author

dstroot commented Mar 31, 2022

@schickling - you rock! Can confirm with a couple twists. First, it didn't work if I had ".js" at the end my require(). Mine works like this:
Screen Shot 2022-03-30 at 5 15 45 PM

Second, I needed to now import React and ReactDOM, not typically needed in a Nextjs project:
Screen Shot 2022-03-30 at 5 16 51 PM

After that I can build successfully with React 18! What?!! Yup!!

@jamesthesken
Copy link

jamesthesken commented Mar 31, 2022

Thank you both for posting those workarounds!

For some reason it is not working as expected on my end. Even with a similar setup as @dstroot.

Did you have to install jsx-runtime through npm?

Edit: Sorry, I had forgot to modify line 17 as you have above...

@dstroot
Copy link
Author

dstroot commented Mar 31, 2022

@jamesthesken - you do not need to install jsx-runtime. It comes with React, although the issue seems to be that React doesn't export it, or rather exports it as jsx_runtime, not jxs_runtime.js.

@Arcath Arcath mentioned this issue Apr 1, 2022
3 tasks
@FradSer
Copy link

FradSer commented Apr 2, 2022

#167 LGTM, upgrade to v9.0.0 works.

@dstroot
Copy link
Author

dstroot commented Apr 4, 2022

Yes, v9.0.0 fixes the issue. Closing.

@dstroot dstroot closed this as completed Apr 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants