prismicio / slice-machine

A series of tools for developing and deploying website sections with Prismic
https://prismic.io/docs
Apache License 2.0
287 stars 53 forks source link

@slicemachine/adapter-next Error: Cannot find module 'react/jsx-runtime' #1006

Closed eunsukimme closed 1 year ago

eunsukimme commented 1 year ago

Versions

Reproduction

I'm using Next.js(v12.3.1) and React/ReactDom(v17.0.2). When I import @slicemachine/adapter-next/simulator, I get an error Error: Cannot find module 'react/jsx-runtime'

Screenshot & package.json
Screenshot 2023-06-13 at 12 25 28 PM ``` { "dependencies": { "@prismicio/client": "^7.1.0", "@prismicio/next": "^0.1.8", "@prismicio/react": "^2.6.2", "@reduxjs/toolkit": "^1.6.2", "next": "12.3.1", "react": "17.0.2", "react-dom": "17.0.2", "react-redux": "^7.2.6", }, "devDependencies": { "@slicemachine/adapter-next": "^0.2.1", "@types/node": "^17.0.30", "@types/react": "17.0.36", "@types/react-dom": "17.0.15", "@types/react-redux": "^7.1.20", "@types/react-slick": "^0.23.8", "slice-machine-ui": "^1.2.0", "typescript": "^4.8.4" } } ```

Steps to reproduce

  1. Install above packages
  2. import import { SliceSimulator } from '@slicemachine/adapter-next/simulator'

What is expected?

Import works nomally.

What is actually happening?

I got Error: Cannot find module 'react/jsx-runtime' error.

Currently @slicemachine/adapter-next/simulator built with automatic JSX runtime. So build result include import { jsx } from "react/jsx-runtime"; but It occurs error on esm from Webpack 5 / Node.js using React v17. So I suggest change vite configuration of this package to use classic jsx runtime to support this environments.

react({ jsxRuntime: 'classic' })
angeloashmore commented 1 year ago

Thanks for the report, @eunsukimme!

Is there a reason you are sticking to React 17 and not upgrading to React 18?

Since this is a version-specific issue, could you provide a minimal reproduction of the issue?

eunsukimme commented 1 year ago

Hi @angeloashmore!

Actually this error occurs on my company codebase, and there are many teams collaborating on the codebase. So I think it's not easy to migrate React version in the near future. So I created this issue and suggested a solution at library-level to edit build configuration of @slicemachine/adapter-next/simulator.

Now I'll make a minimal reproduction of the issue.

mdeclercq commented 1 year ago

Hi @eunsukimme,

I am doing some QA on this issue, did you have a chance to create minimal reproduction of the issue?

Thanks,

mdeclercq commented 1 year ago

Hi @eunsukimme,

We're closing this issue for now. Let us know if it is still blocking and we'll re open it.

Thanks