-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
"Error: Cannot find module 'react/jsx-runtime'" when consuming Parcel's multi-module React component library in Next.js project created by "yarn create next-app" command #8069
Comments
Actually that's not a problem with Parcel, but React itself. As far as I know it has been fixed in React v18, but unfortunately never backported to v17. This import bug only occurs when using Webpack 5 as its resolving algorithm has been updated and now it expects either a full path with file extension or an entry in "exports" map. Neither is present in React v17. |
@V3RON Thanks for replying, I really appreciate that. I think that's not an issue 馃. Because with the same code I provided above, if I use rollup.js or webpack to bundle, it works just fine. Also, I just tried to upgrade react to 18 for both next and the library project. I still got the same issue. |
@Thienhuynh95 Could you share your Rollup/Webpack configuration? I would like to look into it. I'm really curious what's happening if it's really working in those, but not in Parcel. 馃 |
@V3RON Yes, absolutely, I'm happy to do that. |
@Thienhuynh95 Well, both branches work just fine on my side. Not sure why 馃し However, I noticed your Rollup branch uses old |
@V3RON I tried your suggestion, changed 'react' to 'react-jsx', but it's not working as it supposed to. And it's weird that you can't reproduce the issue 馃ゲ |
I gave up and switched over to rollup. I will close this ticket. Thanks everyone for helping, I really appreciate it. |
Even though this issue is closed, I want to comment about what worked for me. I was having both |
@djuretic I think |
is there a solution to this? |
As I tested,
|
@tylerlong Are you building a library or a webapp? For a webapp, you should never see |
It's complicated. It's an electron app with both webapp part and node.js part. It does have a main field because electron requires it. |
馃悰 bug report
Error "Cannot find module 'react/jsx-runtime'" happens when consuming Parcel's multi-module React component library in a Next.js project. I already spent a week just to fix this build, I really like developing Parcel API, so I really appreciate any help/suggestion to make this work 馃槩 . I tried to adjust
engines
in the parcel config,context
field, add/removetargets
, but it doesn't seem to work (it can build but Next.js couldn't consume it - alway get an error like "Can't find module '...'"), also when I include "react" inincludeModules
field or setincludeModules
totrue
, it produced the error "Can't have more than 1 copy of React...".馃帥 Configuration (.babelrc, package.json, cli command)
.babelrc
:.babelrc
in my project, I just use default babel configuration in@parcel/config-default
.package.json
:build.ts
: (parcel config)馃 Expected Behavior
No runtime exception. The library should be able to be consumed in the Next.js project.
Be able to import components from the
reproduce-parcel-issue
library in the Next.js project:馃槸 Current Behavior
Produced error "Cannot find module 'react/jsx-runtime'" when access to dev url
localhost:3000
after ranyarn dev
in Next.js project.Stack traces:
馃拋 Possible Solution
I don't know if this is the issue with Parcel or Next.js configuration. Maybe making the right configuration options in the Parcel API to either generate the bundled script can be used on the client side (be able to use shared modules (react, react-dom, styled-components, ...) on the browser) or make Next.js to be able to consume the library directly (like importing it as if it's an internal code in Next.js project when the library's not bundled and minified) before building pages 馃拋
馃敠 Context
I'm trying to create a public multi-module React component library that would be consumed by the Next.js project. I want to separate the modules, so the consumers don't need to import everything when they just want to consume just one component in the big module. And the way I use Parcel to bundle in my mini project is by writing a script
build.ts
that use Parcel API.The script
build.ts
will just loop through the module configs list and call Parcel API to bundle it.馃捇 Code Sample
Repositories:
Step to reproduce:
dist
folderyarn && yarn build
create-next-app
).dist
folder from "Parcel bundling sample script" project over the Next.js project, run command below in Next.js project's terminal to install local module in project's dependenciesnode_modules
and build dev server:yarn && yarn dev
馃實 Your Environment
Update
With same configuration, I tried to bundle project with Rollup and it works perfectly when I use the library in the next project. I added building process for using Rollup.js to bundle in this repository Parcel bundling sample script on branch
feat/rollup-test
.Step to reproduce:
feat/rollup-test
yarn && yarn build:rollup
dist
folder from "Parcel bundling sample script" project over the Next.js project, run command below in Next.js project's terminal to install local module in project's dependenciesnode_modules
and build dev server:yarn && yarn dev
The text was updated successfully, but these errors were encountered: