Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/react-scripts/bin/react-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@

'use strict';

// Check Node.js version early for clearer errors (see #5430)
const currentNodeVersion = process.versions.node;
const [major] = currentNodeVersion.split('.');
if (Number(major) < 14) {
console.error(
'You are running Node ' +
currentNodeVersion +
'.\n' +
'react-scripts requires Node 14 or higher. \n' +
'Please update your version of Node.'
);
process.exit(1);
}

// Makes the script crash on unhandled rejections instead of silently
// ignoring them. In the future, promise rejections that are not handled will
// terminate the Node.js process with a non-zero exit code.
Expand Down
23 changes: 22 additions & 1 deletion packages/react-scripts/scripts/eject.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,29 @@ prompts({

// Add Babel config
console.log(` Adding ${cyan('Babel')} preset`);
// Detect if the new JSX transform is available and prefer it after eject
const hasJsxRuntime = (() => {
if (process.env.DISABLE_NEW_JSX_TRANSFORM === 'true') {
return false;
}
try {
require.resolve('react/jsx-runtime');
return true;
} catch (e) {
return false;
}
})();

appPackage.babel = {
presets: ['react-app'],
// Preserve preset with explicit runtime so ejected apps keep working without importing React
presets: [
[
'react-app',
{
runtime: hasJsxRuntime ? 'automatic' : 'classic',
},
],
],
};

// Add ESlint config
Expand Down