fix: don't fail entire build when gatsby-config fails to be imported #562
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Build plugin tries to load
gatsby-config.js
to inspect list of gatsby plugins, ensure thatgatsby-plugin-netlify
is used and that version is compatible etc. It's currently only meant (?) to generate warning logs when it finds incompatibilities, but incompatibilities themselves are not causing builds to fail.Current config loading logic does fail entire build if it fails to
require
gatsby-config.js
and this might happen if user is authoring it in ESM, still uses.js
extension (and notype: "module"
in package json) and uses tools likeesm
,@babel/register
etc to support that syntax in the build command.The config checks in this plugin currently also are not handling some other
gatsby-config
variants that Gatsby itself support now:gatsby-config.ts
( https://www.gatsbyjs.com/docs/reference/release-notes/v4.9/#support-for-typescript-in-gatsby-config-and-gatsby-node )gatsby-config.mjs
( https://www.gatsbyjs.com/docs/reference/release-notes/v5.3/#es-modules-esm-in-gatsby-files )With above in mind (plugins validation is already not happening in some cases) +
@netlify/plugin-gatsby
being installed automatically it might make sense to make failures to load config not fatal (at least for now) (?)Test plan
gatsby@3
, withgatsby-config.js
using ESM and using following build commandNODE_OPTIONS="-r esm" gatsby build
.Relevant links (GitHub issues, Notion docs, etc.) or a picture of cute animal
Fixes #559
Standard checks:
🧪 Once merged, make sure to update the version if needed and that it was
published correctly.