question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@babel/plugin-transform-react-jsx: automatic runtime import is added at the start

See original GitHub issue

Bug 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:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
akgupta0777commented, Dec 21, 2020

@eps1lon ohh I got it. Thanks for explaination

1reaction
nicolo-ribaudocommented, Dec 17, 2020

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found