File tree Expand file tree Collapse file tree 4 files changed +35
-4
lines changed
cli/uni-builder/src/webpack/plugins
runtime/plugin-testing/src/base/config/transformer Expand file tree Collapse file tree 4 files changed +35
-4
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' @modern-js/plugin-testing ' : patch
3+ ' @modern-js/uni-builder ' : patch
4+ ' @modern-js/utils ' : patch
5+ ---
6+
7+ fix: React is undefined while using react@16.14.0 and webpack mode
8+ fix: 使用 react@16.14.0 且在 webpack 模式下时报错 React is undefined
Original file line number Diff line number Diff line change 11import type { BabelConfig } from '@modern-js/babel-preset' ;
22import { getBabelConfigForNode } from '@modern-js/babel-preset/node' ;
33import { getBabelConfigForWeb } from '@modern-js/babel-preset/web' ;
4- import { applyOptionsChain , isBeyondReact17 } from '@modern-js/utils' ;
4+ import { applyOptionsChain , isSupportAutomaticJsx } from '@modern-js/utils' ;
55import { logger } from '@rsbuild/core' ;
66import type {
77 NormalizedEnvironmentConfig ,
@@ -25,7 +25,7 @@ import {
2525 * webpack mode: uni-builder:babel -> uni-builder:ts-loader -> rsbuild-webpack:swc
2626 */
2727export const getPresetReact = ( rootPath : string , isProd : boolean ) => {
28- const isNewJsx = isBeyondReact17 ( rootPath ) ;
28+ const isNewJsx = isSupportAutomaticJsx ( rootPath ) ;
2929
3030 const presetReactOptions = {
3131 development : ! isProd ,
Original file line number Diff line number Diff line change 1- import { isBeyondReact17 } from '@modern-js/utils' ;
1+ import { isSupportAutomaticJsx } from '@modern-js/utils' ;
22import babelJest from 'babel-jest' ;
33
4- const isNewJsx = isBeyondReact17 ( process . cwd ( ) ) ;
4+ const isNewJsx = isSupportAutomaticJsx ( process . cwd ( ) ) ;
55
66const babelTransformer = ( babelJest . createTransformer as any ) ?.( {
77 presets : [
Original file line number Diff line number Diff line change @@ -79,6 +79,9 @@ export const isWebOnly = async () => {
7979 return Boolean ( options [ 'web-only' ] ) ;
8080} ;
8181
82+ /**
83+ * @deprecated Use {@link isSupportAutomaticJsx} to check if the project supports automatic JSX instead.
84+ */
8285export const isBeyondReact17 = ( cwd : string ) => {
8386 const pkgPath = pkgUp . sync ( { cwd } ) ;
8487
@@ -99,6 +102,26 @@ export const isBeyondReact17 = (cwd: string) => {
99102 return semver . satisfies ( semver . minVersion ( deps . react ) ! , '>=17.0.0' ) ;
100103} ;
101104
105+ export const isSupportAutomaticJsx = ( cwd : string ) => {
106+ const pkgPath = pkgUp . sync ( { cwd } ) ;
107+
108+ if ( ! pkgPath ) {
109+ return false ;
110+ }
111+
112+ const pkgInfo = JSON . parse ( fs . readFileSync ( pkgPath , 'utf8' ) ) ;
113+ const deps = {
114+ ...pkgInfo . devDependencies ,
115+ ...pkgInfo . dependencies ,
116+ } ;
117+
118+ if ( typeof deps . react !== 'string' ) {
119+ return false ;
120+ }
121+
122+ return semver . satisfies ( semver . minVersion ( deps . react ) ! , '>=16.14.0' ) ;
123+ } ;
124+
102125export const isReact18 = ( cwd : string = process . cwd ( ) ) => {
103126 const pkgPath = path . join ( cwd , 'package.json' ) ;
104127
You can’t perform that action at this time.
0 commit comments