Importing react/jsx-runtime breaks dev builds
See original GitHub issueDescribe the bug
When importing react/jsx-runtime
, dev build breaks with the following client error:
Uncaught ReferenceError: module is not defined
at jsx-runtime.js:6
In my more complex setup I am consuming a local prebuilt library and get a more weird error message
Uncaught ReferenceError: module is not defined
at null:6
I’ve found out that setting optimizeDeps.include: ['react/jsx-runtime']
fixes this issue and in fact 'react/jsx-dev-runtime'
works because @vitejs/plugin-react
adds it by default. Does it make sense to also include 'react/jsx-runtime'
there?
Reproduction
System Info
System:
OS: macOS 12.0.1
CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
Memory: 69.96 MB / 16.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 16.13.0 - ~/.volta/tools/image/node/16.13.0/bin/node
Yarn: 1.18.0 - ~/.volta/tools/image/yarn/1.18.0/bin/yarn
npm: 8.1.0 - ~/.volta/tools/image/node/16.13.0/bin/npm
Watchman: 2021.06.07.00 - /usr/local/bin/watchman
Browsers:
Chrome: 96.0.4664.110
Edge: 96.0.1054.62
Firefox: 95.0
Safari: 15.1
npmPackages:
@vitejs/plugin-react: ~1.1.3 => 1.1.3
vite: ~2.7.4 => 2.7.4
Used Package Manager
npm
Logs
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it’s a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/vue-next instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:11
- Comments:14 (3 by maintainers)
Top Results From Across the Web
Introducing the New JSX Transform – React Blog
Instead of transforming JSX to React.createElement , the new JSX transform automatically imports special functions from those new entry points ...
Read more >can't resolve react/jsx-dev-runtime' after changing "type":"
BREAKING CHANGE: The request 'react/jsx-dev-runtime' failed to resolve only because it was resolved as fully specified (probably because the ...
Read more >API - ESBuild
There are two main API calls in esbuild's API: transform and build. ... JSX dev; JSX factory; JSX fragment; JSX import source; JSX...
Read more >cannot find module '@emotion/react/jsx-runtime' or its ...
If you're still getting the "Cannot find module 'react/jsx-runtime' or its corresponding type declarations" error, open your package.json file and make sure it ......
Read more >babel/plugin-transform-react-jsx
Automatic runtime is a feature added in v7.9.0 . With this runtime enabled, the functions that JSX compiles to will be imported automatically....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Change the configuration of your
@vitejs/plugin-react
instance to the classic mode of thejsxRuntime
vite.config.js
Reference
Opting out of the automatic JSX runtime
For me this proposed solution works as a temporary hotfix:
Will your PR covers this issue @aleclarson? Thank you!