Skip to content

Commit 46732f2

Browse files
committed
fix(eject): preserve React 17 automatic JSX runtime in Babel config after eject
1 parent 6254386 commit 46732f2

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

packages/react-scripts/scripts/eject.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,29 @@ prompts({
237237

238238
// Add Babel config
239239
console.log(` Adding ${cyan('Babel')} preset`);
240+
// Detect if the new JSX transform is available and prefer it after eject
241+
const hasJsxRuntime = (() => {
242+
if (process.env.DISABLE_NEW_JSX_TRANSFORM === 'true') {
243+
return false;
244+
}
245+
try {
246+
require.resolve('react/jsx-runtime');
247+
return true;
248+
} catch (e) {
249+
return false;
250+
}
251+
})();
252+
240253
appPackage.babel = {
241-
presets: ['react-app'],
254+
// Preserve preset with explicit runtime so ejected apps keep working without importing React
255+
presets: [
256+
[
257+
'react-app',
258+
{
259+
runtime: hasJsxRuntime ? 'automatic' : 'classic',
260+
},
261+
],
262+
],
242263
};
243264

244265
// Add ESlint config

0 commit comments

Comments
 (0)