Skip to content

Commit

Permalink
fix(gatsby): add runtime check for react 17 (#27468)
Browse files Browse the repository at this point in the history
  • Loading branch information
wardpeet committed Oct 15, 2020
1 parent 1656152 commit 239d539
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/gatsby/src/utils/webpack-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import MiniCssExtractPlugin from "mini-css-extract-plugin"
import OptimizeCssAssetsPlugin from "optimize-css-assets-webpack-plugin"
import ReactRefreshWebpackPlugin from "@pmmmwh/react-refresh-webpack-plugin"
import { getBrowsersList } from "./browserslist"
import semver from "semver"

import { GatsbyWebpackStatsExtractor } from "./gatsby-webpack-stats-extractor"
import { GatsbyWebpackEslintGraphqlSchemaReload } from "./gatsby-webpack-eslint-graphql-schema-reload-plugin"
Expand Down Expand Up @@ -721,7 +722,13 @@ function reactHasJsxRuntime(): boolean {
// Not every version of React has this jsx-runtime yet. Eventually,
// it will be backported to older versions of react and this check
// will become unnecessary.
return !!require.resolve(`react/jsx-runtime.js`)

// for now we also do the semver check until react 17 is more widely used
const react = require(`react/package.json`)
return (
!!require.resolve(`react/jsx-runtime.js`) &&
semver.major(react.version) >= 17
)
} catch (e) {
// If the require.resolve throws, that means this version of React
// does not support the jsx runtime.
Expand Down

0 comments on commit 239d539

Please sign in to comment.