Skip to content

Commit 92ce524

Browse files
committed
fix: resolve new JSX runtime issues
1 parent d5c0fe2 commit 92ce524

File tree

3 files changed

+24
-19
lines changed

3 files changed

+24
-19
lines changed

packages/babel-preset-react-app/create.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@
88

99
const path = require('path');
1010

11+
const hasJsxRuntime = (() => {
12+
try {
13+
require.resolve('react/jsx-runtime.js');
14+
return true;
15+
} catch (e) {
16+
return false;
17+
}
18+
})();
19+
1120
const validateBoolOption = (name, value, defaultValue) => {
1221
if (typeof value === 'undefined') {
1322
value = defaultValue;
@@ -54,10 +63,6 @@ module.exports = function (api, opts, env) {
5463
);
5564
}
5665

57-
var hasJsxRuntime = Boolean(
58-
api.caller(caller => !!caller && caller.hasJsxRuntime)
59-
);
60-
6166
if (!isEnvDevelopment && !isEnvProduction && !isEnvTest) {
6267
throw new Error(
6368
'Using `babel-preset-react-app` requires that you specify `NODE_ENV` or ' +
@@ -100,7 +105,7 @@ module.exports = function (api, opts, env) {
100105
// Will use the native built-in instead of trying to polyfill
101106
// behavior for any plugins that require one.
102107
...(!hasJsxRuntime ? { useBuiltIns: true } : {}),
103-
runtime: opts.runtime || 'classic',
108+
runtime: hasJsxRuntime ? 'automatic' : 'classic',
104109
},
105110
],
106111
isTypeScriptEnabled && [require('@babel/preset-typescript').default],

packages/eslint-config-react-app/base.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@
1111
// React App support, and is used as the `baseConfig` for `eslint-loader`
1212
// to ensure that user-provided configs don't need this boilerplate.
1313

14+
const hasJsxRuntime = (() => {
15+
try {
16+
require.resolve('react/jsx-runtime.js');
17+
return true;
18+
} catch (e) {
19+
return false;
20+
}
21+
})();
22+
1423
module.exports = {
1524
root: true,
1625

@@ -41,8 +50,10 @@ module.exports = {
4150
},
4251

4352
rules: {
44-
'react/jsx-uses-react': 'warn',
4553
'react/jsx-uses-vars': 'warn',
46-
'react/react-in-jsx-scope': 'error',
54+
...(!hasJsxRuntime && {
55+
'react/jsx-uses-react': 'warn',
56+
'react/react-in-jsx-scope': 'error',
57+
}),
4758
},
4859
};

packages/react-scripts/config/webpack.config.js

+1-12
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ const fs = require('fs');
1212
const path = require('path');
1313
const webpack = require('webpack');
1414
const resolve = require('resolve');
15-
const semver = require('semver');
1615
const PnpWebpackPlugin = require('pnp-webpack-plugin');
1716
const HtmlWebpackPlugin = require('html-webpack-plugin');
1817
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
@@ -34,7 +33,6 @@ const ModuleNotFoundPlugin = require('react-dev-utils/ModuleNotFoundPlugin');
3433
const ForkTsCheckerWebpackPlugin = require('react-dev-utils/ForkTsCheckerWebpackPlugin');
3534
const typescriptFormatter = require('react-dev-utils/typescriptFormatter');
3635
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
37-
const react = require(require.resolve('react', { paths: [paths.appPath] }));
3836
// @remove-on-eject-begin
3937
const getCacheIdentifier = require('react-dev-utils/getCacheIdentifier');
4038
// @remove-on-eject-end
@@ -403,16 +401,7 @@ module.exports = function (webpackEnv) {
403401
// @remove-on-eject-begin
404402
babelrc: false,
405403
configFile: false,
406-
presets: [
407-
[
408-
require.resolve('babel-preset-react-app'),
409-
{
410-
runtime: semver.gte(react.version, '17.0.0-alpha.0')
411-
? 'automatic'
412-
: 'classic',
413-
},
414-
],
415-
],
404+
presets: [require.resolve('babel-preset-react-app')],
416405
// Make sure we have a unique cache identifier, erring on the
417406
// side of caution.
418407
// We remove this when the user ejects because the default

0 commit comments

Comments
 (0)