File tree Expand file tree Collapse file tree 1 file changed +18
-2
lines changed
packages/react-scripts/scripts/utils Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,19 @@ const semver = require('semver');
18
18
const immer = require ( 'react-dev-utils/immer' ) . produce ;
19
19
const globby = require ( 'react-dev-utils/globby' ) . sync ;
20
20
21
+ const hasJsxRuntime = ( ( ) => {
22
+ if ( process . env . DISABLE_NEW_JSX_TRANSFORM === 'true' ) {
23
+ return false ;
24
+ }
25
+
26
+ try {
27
+ require . resolve ( 'react/jsx-runtime' , { paths : [ paths . appPath ] } ) ;
28
+ return true ;
29
+ } catch ( e ) {
30
+ return false ;
31
+ }
32
+ } ) ( ) ;
33
+
21
34
function writeJson ( fileName , object ) {
22
35
fs . writeFileSync (
23
36
fileName ,
@@ -134,8 +147,11 @@ function verifyTypeScriptSetup() {
134
147
noEmit : { value : true } ,
135
148
jsx : {
136
149
parsedValue : ts . JsxEmit . React ,
137
- value : semver . gte ( ts . version , '4.1.0-beta' ) ? 'react-jsx' : 'react' ,
138
- reason : 'to support the new JSX transform in React 17'
150
+ value :
151
+ hasJsxRuntime && semver . gte ( ts . version , '4.1.0-beta' )
152
+ ? 'react-jsx'
153
+ : 'react' ,
154
+ reason : 'to support the new JSX transform in React 17' ,
139
155
} ,
140
156
paths : { value : undefined , reason : 'aliased imports are not supported' } ,
141
157
} ;
You can’t perform that action at this time.
0 commit comments