Skip to content

Commit

Permalink
fix(gatsby): remove resource query from warnings (#36439)
Browse files Browse the repository at this point in the history
remove resource query from warning
  • Loading branch information
marvinjude committed Aug 23, 2022
1 parent 0d896ae commit 1bf2358
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions packages/gatsby/src/utils/webpack-error-utils.ts
Expand Up @@ -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<WebpackError>
Expand All @@ -150,9 +162,13 @@ export const reportWebpackWarnings = (
let warningMessages: Array<string> = []
if (typeof warnings[0] === `string`) {
warningMessages = warnings as unknown as Array<string>
} 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)
Expand Down

0 comments on commit 1bf2358

Please sign in to comment.