From f05eb6f32ef0a2160bb11077de556a606a15b326 Mon Sep 17 00:00:00 2001 From: Jude Agboola Date: Mon, 22 Aug 2022 12:31:51 +0100 Subject: [PATCH] remove resource query from warning --- .../gatsby/src/utils/webpack-error-utils.ts | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/packages/gatsby/src/utils/webpack-error-utils.ts b/packages/gatsby/src/utils/webpack-error-utils.ts index ac16ce191921a..e6fb2ce275ddf 100644 --- a/packages/gatsby/src/utils/webpack-error-utils.ts +++ b/packages/gatsby/src/utils/webpack-error-utils.ts @@ -132,6 +132,18 @@ const transformWebpackError = ( } } +// With the introduction of Head API, the modulePath can have a resourceQuery so this function can be used to remove it +const removeResourceQuery = ( + moduleName: string | undefined +): string | undefined => { + const moduleNameWithoutQuery = moduleName?.replace( + /(\?|&)export=(default|head)$/, + `` + ) + + return moduleNameWithoutQuery +} + export const structureWebpackErrors = ( stage: StageEnum, webpackError: WebpackError | Array @@ -150,9 +162,13 @@ export const reportWebpackWarnings = ( let warningMessages: Array = [] if (typeof warnings[0] === `string`) { warningMessages = warnings as unknown as Array - } else if (warnings[0]?.message && warnings[0]?.moduleName) { + } else if ( + warnings[0]?.message && + removeResourceQuery(warnings[0]?.moduleName) + ) { warningMessages = warnings.map( - warning => `${warning.moduleName}\n\n${warning.message}` + warning => + `${removeResourceQuery(warning.moduleName)}\n\n${warning.message}` ) } else if (warnings[0]?.message) { warningMessages = warnings.map(warning => warning.message)