From 33415c821bf9546aa3d1ac62afb75b9ffeb67a76 Mon Sep 17 00:00:00 2001 From: Kyle Mathews Date: Mon, 12 Apr 2021 10:12:32 -0700 Subject: [PATCH] fix(gatsby): webpack warnings are no longer in object format by default (#30801) * fix(gatsby): webpack warnings are no longer in object format by default * Fix (maybe) Typescript errors --- packages/gatsby/src/commands/build.ts | 3 ++- packages/gatsby/src/services/start-webpack-server.ts | 3 ++- packages/gatsby/src/utils/webpack-error-utils.ts | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) 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)