From 41b3e909908b7e1b2e36fba92da1c002febce243 Mon Sep 17 00:00:00 2001 From: Kyle Mathews Date: Mon, 10 May 2021 23:00:16 -0700 Subject: [PATCH] fix(gatsby): Pass reporter from functions code for reporting warning (#31336) * fix(gatsby): Pass reporter from functions code for reporting warning Also include the file that the warning is for in the message * Update packages/gatsby/src/internal-plugins/functions/gatsby-node.ts Co-authored-by: Ward Peeters Co-authored-by: Ward Peeters (cherry picked from commit f09fae8f415a018f60abb56fff017f574ae8c871) --- packages/gatsby/src/internal-plugins/functions/gatsby-node.ts | 2 +- packages/gatsby/src/utils/webpack-error-utils.ts | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/gatsby/src/internal-plugins/functions/gatsby-node.ts b/packages/gatsby/src/internal-plugins/functions/gatsby-node.ts index 7c11342c90888..ca5506df6906d 100644 --- a/packages/gatsby/src/internal-plugins/functions/gatsby-node.ts +++ b/packages/gatsby/src/internal-plugins/functions/gatsby-node.ts @@ -220,7 +220,7 @@ export async function onPreBootstrap({ function callback(err, stats): any { const rawMessages = stats.toJson({ moduleTrace: false }) if (rawMessages.warnings.length > 0) { - reporter.warn(reportWebpackWarnings(rawMessages.warnings)) + reportWebpackWarnings(rawMessages.warnings, reporter) } if (err) return reject(err) diff --git a/packages/gatsby/src/utils/webpack-error-utils.ts b/packages/gatsby/src/utils/webpack-error-utils.ts index c01d5b9aef7bb..6c00bae073297 100644 --- a/packages/gatsby/src/utils/webpack-error-utils.ts +++ b/packages/gatsby/src/utils/webpack-error-utils.ts @@ -148,7 +148,9 @@ export const reportWebpackWarnings = ( warnings: StatsCompilation["warnings"] = [], reporter: Reporter ): void => { - const warningMessages = warnings.map(warning => warning.message) + const warningMessages = warnings.map( + warning => `${warning.moduleName}\n\n${warning.message}` + ) formatWebpackMessages({ errors: [],