From 96dc88aa8cef36a16d41f16e415c0e82606806e1 Mon Sep 17 00:00:00 2001 From: Kyle Mathews Date: Mon, 14 Jun 2021 00:22:25 -0700 Subject: [PATCH] fix(gatsby): infer shape of warning object (#31489) Co-authored-by: Vladimir Razuvaev Co-authored-by: gatsbybot --- packages/gatsby/src/utils/webpack-error-utils.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/gatsby/src/utils/webpack-error-utils.ts b/packages/gatsby/src/utils/webpack-error-utils.ts index 6c00bae073297..d35e7d647ac31 100644 --- a/packages/gatsby/src/utils/webpack-error-utils.ts +++ b/packages/gatsby/src/utils/webpack-error-utils.ts @@ -148,9 +148,16 @@ export const reportWebpackWarnings = ( warnings: StatsCompilation["warnings"] = [], reporter: Reporter ): void => { - const warningMessages = warnings.map( - warning => `${warning.moduleName}\n\n${warning.message}` - ) + let warningMessages: Array = [] + if (typeof warnings[0] === `string`) { + warningMessages = (warnings as unknown) as Array + } else if (warnings[0]?.message && warnings[0]?.moduleName) { + warningMessages = warnings.map( + warning => `${warning.moduleName}\n\n${warning.message}` + ) + } else if (warnings[0]?.message) { + warningMessages = warnings.map(warning => warning.message) + } formatWebpackMessages({ errors: [],