New JSX transform doesn't work when using react v17+
See original GitHub issue🐛 bug report
react v17+ removes the need for import React from "react";
statements but looks like the zero-config of Parcel doesn’t work with it.
🎛 Configuration (.babelrc, package.json, cli command)
.babelrc: none
// package.json
...
"react": "^17.0.1",
"react-dom": "^17.0.1",
...
CLI command: "parcel serve ./app/index.html --port 3000"
🤔 Expected Behavior
Below code should work fine when using react v17+
import { render } from "react-dom";
render(
<h1>Hello World</h1>,
document.getElementById("root")
);
😯 Current Behavior
Nothing is rendered on the screen. Browser console error says “React is not defined”
💁 Possible Solution
This config works: https://stackoverflow.com/a/67759434/7435656
🔦 Context
Migrating existing codebase from create-react-app to parcel. Followed the Generic Webapp guide from the docs but it doesn’t look like those steps work for projects using the new JSX transform.
💻 Code Sample
Adding import React from "react";
makes the application work but that shouldn’t be required when using react v17+
🌍 Your Environment
Software | Version(s) |
---|---|
Parcel | ^2.0.0-beta.3.1 |
Node | v14.17.0 |
npm/Yarn | 6.14.13 |
Operating System | Ubuntu 20 LTS |
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Introducing the New JSX Transform – React Blog
When you use JSX, the compiler transforms it into React function calls that the browser can understand. The old JSX transform turned JSX...
Read more >React.js 17: No New Features and New JSX Transform
This means, that if your app is running React 17 and you need to upgrade some features to React 18, you can move...
Read more >JSX import fixes do not support new React JSX Transform ...
One workaround I found is: Instead of pressing cmd+. to open the auto suggest panel, remove the last letter of the component and...
Read more >How to enable new JSX transform in React?
Yes! You'll no longer need to import React to each. and. every. component. you write. Instead, it will be imported automatically!
Read more >How to Use New JSX Transform IN REACT - Aspire Blogs
React doesn't require using JSX, but most people find it helpful as a visible aid when working with UI inside the JavaScript code....
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 Free
Top 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
Ah I see. We could detect the react version and do this automatically I guess.
Does that environment support the new automatic jsx runtime? https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html
Disabling that in a jsconfig or tsconfig config might work (so that the traditional
React.createElement
is used)