Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gatsby): fix fs empty webpack5 deprecation #29631

Merged
merged 7 commits into from
Feb 22, 2021
Merged
Show file tree
Hide file tree
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
11 changes: 9 additions & 2 deletions packages/gatsby-cli/src/structured-errors/error-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,15 @@ const errors = {
level: Level.ERROR,
},
"98124": {
text: (context): string =>
`${context.stageLabel} failed\n\n${context.sourceMessage}\n\nIf you're trying to use a package make sure that '${context.packageName}' is installed. If you're trying to use a local file make sure that the path is correct.`,
text: (context): string => {
let message = `${context.stageLabel} failed\n\n${context.sourceMessage}\n\nIf you're trying to use a package make sure that '${context.packageName}' is installed. If you're trying to use a local file make sure that the path is correct.`

if (context.deprecationReason) {
message += `\n\n${context.deprecationReason}`
}

return message
},
type: Type.WEBPACK,
level: Level.ERROR,
category: ErrorCategory.USER,
Expand Down
24 changes: 24 additions & 0 deletions packages/gatsby/src/redux/actions/public.js
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,18 @@ actions.createParentChildLink = (
* @param {Object} config partial webpack config, to be merged into the current one
*/
actions.setWebpackConfig = (config: Object, plugin?: ?Plugin = null) => {
if (config.node?.fs === `empty`) {
report.warn(
`[deprecated${
plugin ? ` ` + plugin.name : ``
}] node.fs is deprecated. Please set "resolve.fallback.fs = false".`
)
delete config.node.fs
config.resolve = config.resolve || {}
config.resolve.fallback = config.resolve.fallback || {}
config.resolve.fallback.fs = false
}

return {
type: `SET_WEBPACK_CONFIG`,
plugin,
Expand All @@ -968,6 +980,18 @@ actions.setWebpackConfig = (config: Object, plugin?: ?Plugin = null) => {
* @param {Object} config complete webpack config
*/
actions.replaceWebpackConfig = (config: Object, plugin?: ?Plugin = null) => {
if (config.node?.fs === `empty`) {
report.warn(
`[deprecated${
plugin ? ` ` + plugin.name : ``
}] node.fs is deprecated. Please set "resolve.fallback.fs = false".`
)
delete config.node.fs
config.resolve = config.resolve || {}
config.resolve.fallback = config.resolve.fallback || {}
config.resolve.fallback.fs = false
}

return {
type: `REPLACE_WEBPACK_CONFIG`,
plugin,
Expand Down
11 changes: 11 additions & 0 deletions packages/gatsby/src/utils/webpack-error-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,17 @@ const transformWebpackError = (
id = `98124`
context.packageName = matches?.[1]
context.sourceMessage = matches?.[0]

// get Breaking change message out of error
// it shows extra information for things that changed with webpack
const BreakingChangeRegex = /BREAKING CHANGE[\D\n\d]+$/
if (BreakingChangeRegex.test(castedWebpackError.message)) {
const breakingMatch = castedWebpackError.message.match(
BreakingChangeRegex
)

context.deprecationReason = breakingMatch?.[0]
}
}

return {
Expand Down