Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions packages/gatsby/src/utils/webpack-error-utils.ts
Original file line number Diff line number Diff line change
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