From ba0e466c4ef7b5c19ea2c5ae4affc265d070cc42 Mon Sep 17 00:00:00 2001 From: Ian Sutherland Date: Thu, 22 Oct 2020 21:10:23 -0600 Subject: [PATCH] Also check react version before setting jsx value in tsconfig --- .../scripts/utils/verifyTypeScriptSetup.js | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/packages/react-scripts/scripts/utils/verifyTypeScriptSetup.js b/packages/react-scripts/scripts/utils/verifyTypeScriptSetup.js index b6f7edead4c..9942013ad32 100644 --- a/packages/react-scripts/scripts/utils/verifyTypeScriptSetup.js +++ b/packages/react-scripts/scripts/utils/verifyTypeScriptSetup.js @@ -18,6 +18,19 @@ const semver = require('semver'); const immer = require('react-dev-utils/immer').produce; const globby = require('react-dev-utils/globby').sync; +const hasJsxRuntime = (() => { + if (process.env.DISABLE_NEW_JSX_TRANSFORM === 'true') { + return false; + } + + try { + require.resolve('react/jsx-runtime', { paths: [paths.appPath] }); + return true; + } catch (e) { + return false; + } +})(); + function writeJson(fileName, object) { fs.writeFileSync( fileName, @@ -134,8 +147,11 @@ function verifyTypeScriptSetup() { noEmit: { value: true }, jsx: { parsedValue: ts.JsxEmit.React, - value: semver.gte(ts.version, '4.1.0-beta') ? 'react-jsx' : 'react', - reason: 'to support the new JSX transform in React 17' + value: + hasJsxRuntime && semver.gte(ts.version, '4.1.0-beta') + ? 'react-jsx' + : 'react', + reason: 'to support the new JSX transform in React 17', }, paths: { value: undefined, reason: 'aliased imports are not supported' }, };