From 4eca6cce3b39bbcff95166e3294da1e50b32fdf8 Mon Sep 17 00:00:00 2001 From: GatsbyJS Bot Date: Tue, 11 May 2021 12:12:35 -0400 Subject: [PATCH] fix(gatsby): Pass reporter from functions code for reporting warning (#31336) (#31363) * 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) Co-authored-by: Kyle Mathews --- 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: [],