@babel/plugin-transform-react-jsx: automatic runtime import is added at the start
See original GitHub issueBug Report
Current behavior
Input Code
import 'react-app-polyfill/ie11';
import 'react-app-polyfill/stable';
import ReactDOM from 'react-dom';
ReactDOM.render(
<p>Hello, World!</p>,
document.getElementById('root')
);
Expected behavior
The runtime is not evaluated before the polyfills are applied.
The polyfills contain a polyfill for symbols. However, React uses numbers as fallbacks for its “symbols”. Since react
and its renderer packages don’t share the same symbols but rely on Symbol.for
the symbols in the created react elements will use numbers while the renderer expects Symbols
Babel Configuration (babel.config.js, .babelrc, package.json#babel, cli command, .eslintrc)
See repl
Environment
- Babel version(s): See repl
- Node/npm version: See repl
- OS: See repl
- Monorepo: See repl
- How you are using Babel: See repl
Possible Solution
Add the import after all the existing imports.
Additional context
Originally reported in https://github.com/facebook/react/issues/20481#issuecomment-747708453
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:9 (6 by maintainers)
Top Results From Across the Web
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 >Introducing the New JSX Transform – React Blog
createElement , the new JSX transform automatically imports special ... Starting from Babel 8, "automatic" will be the default runtime for ...
Read more >New jsx compiler? - help - Meteor forums
I've been doing something similar to this for ages, but without the need to have an import inserted by the compiler everywhere (honestly, ......
Read more >React 17 introduces new JSX transform - Saeloun Blog
In React 17 and starting with Babel version v7.9.0 , @babel/plugin-transform-react-jsx plugin automatically imports “special functions” from ...
Read more >Rollup + React 17 with new JSX Transform - Stack Overflow
Fixed this by adding { runtime: "automatic" } to the ... pass {"runtime": "automatic"} as an option to @babel/plugin-transform-react-jsx or ...
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
@eps1lon ohh I got it. Thanks for explaination
All those examples use ES modules, the only problem is when using JSX inside CommonJS files.
EDIT: Ok, I was really bad at explaining myself 😅 We can fix this for ESM, and keep the current behavior for CJS