diff --git a/packages/gatsby/src/commands/build.ts b/packages/gatsby/src/commands/build.ts index 3d99a04f8b517..a08d8e4cf2831 100644 --- a/packages/gatsby/src/commands/build.ts +++ b/packages/gatsby/src/commands/build.ts @@ -128,7 +128,8 @@ module.exports = async function build(program: IBuildArgs): Promise { stats = await buildProductionBundle(program, buildActivityTimer.span) if (stats.hasWarnings()) { - reportWebpackWarnings(stats.compilation.warnings, report) + const rawMessages = stats.toJson({ moduleTrace: false }) + reportWebpackWarnings(rawMessages.warnings, report) } } catch (err) { buildActivityTimer.panic(structureWebpackErrors(Stage.BuildJavascript, err)) diff --git a/packages/gatsby/src/services/start-webpack-server.ts b/packages/gatsby/src/services/start-webpack-server.ts index 6698b31938a8b..e52c4fcbcca80 100644 --- a/packages/gatsby/src/services/start-webpack-server.ts +++ b/packages/gatsby/src/services/start-webpack-server.ts @@ -112,7 +112,8 @@ export async function startWebpackServer({ if (webpackActivity) { if (stats.hasWarnings()) { - reportWebpackWarnings(stats.compilation.warnings, report) + const rawMessages = stats.toJson({ moduleTrace: false }) + reportWebpackWarnings(rawMessages.warnings, report) } if (!isSuccessful) { diff --git a/packages/gatsby/src/utils/webpack-error-utils.ts b/packages/gatsby/src/utils/webpack-error-utils.ts index 168ad91b3d901..c01d5b9aef7bb 100644 --- a/packages/gatsby/src/utils/webpack-error-utils.ts +++ b/packages/gatsby/src/utils/webpack-error-utils.ts @@ -1,5 +1,5 @@ import { Reporter } from "gatsby-cli/lib/reporter/reporter" -import { WebpackError, Module, NormalModule } from "webpack" +import { WebpackError, StatsCompilation, Module, NormalModule } from "webpack" import { Stage as StageEnum } from "../commands/types" import formatWebpackMessages from "react-dev-utils/formatWebpackMessages" @@ -145,7 +145,7 @@ export const structureWebpackErrors = ( } export const reportWebpackWarnings = ( - warnings: Array, + warnings: StatsCompilation["warnings"] = [], reporter: Reporter ): void => { const warningMessages = warnings.map(warning => warning.message)