Skip to content

Commit 239d539

Browse files
authoredOct 15, 2020
fix(gatsby): add runtime check for react 17 (#27468)
1 parent 1656152 commit 239d539

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed
 

‎packages/gatsby/src/utils/webpack-utils.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import MiniCssExtractPlugin from "mini-css-extract-plugin"
99
import OptimizeCssAssetsPlugin from "optimize-css-assets-webpack-plugin"
1010
import ReactRefreshWebpackPlugin from "@pmmmwh/react-refresh-webpack-plugin"
1111
import { getBrowsersList } from "./browserslist"
12+
import semver from "semver"
1213

1314
import { GatsbyWebpackStatsExtractor } from "./gatsby-webpack-stats-extractor"
1415
import { GatsbyWebpackEslintGraphqlSchemaReload } from "./gatsby-webpack-eslint-graphql-schema-reload-plugin"
@@ -721,7 +722,13 @@ function reactHasJsxRuntime(): boolean {
721722
// Not every version of React has this jsx-runtime yet. Eventually,
722723
// it will be backported to older versions of react and this check
723724
// will become unnecessary.
724-
return !!require.resolve(`react/jsx-runtime.js`)
725+
726+
// for now we also do the semver check until react 17 is more widely used
727+
const react = require(`react/package.json`)
728+
return (
729+
!!require.resolve(`react/jsx-runtime.js`) &&
730+
semver.major(react.version) >= 17
731+
)
725732
} catch (e) {
726733
// If the require.resolve throws, that means this version of React
727734
// does not support the jsx runtime.

0 commit comments

Comments
 (0)
Please sign in to comment.