-
Notifications
You must be signed in to change notification settings - Fork 11
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
Breaking: Upgrade Gatsby to latest version 5. #186
Conversation
❌ Deploy Preview for tattle-website-preview failed. Why did it fail? →
|
@maanasb01 the netlify build seems to be failing because it was using older version of node to build the site. I have upgraded node version on netlify. You might need to push again to trigger a build. Since its a major commit, I'd like to make sure the preview build on netlify is passing so i can test all important pages. |
@dennyabrain Done! |
@dennyabrain It appears that the version which is being used is still 16.20.2 |
@dennyabrain Yeah sure! Can it depend on deploy-production.yml file? In that file, the mentioned node version is still 16. In this PR I have changed it to 18. |
Hmmm, I don't think so. But regardless I have updated the version in the workflow file as well and merged in main. |
@dennyabrain Yeah you were right, it did not work. I pushed a new commit and it failed again with the same error (the version compatibility one). |
I have pulled the PR locally and built it and checked it. I am merging it to check the possiblity that maybe netlify is failing because of some old data/caching issue. Will watch out for next PR |
Great! Glad it worked out! |
Upgradation to Version 5 Notes
Table of Contents
fields
propertyfileAbsolutePath
is deprecatedchildImageSharp
gatsby-plugin-mdx
latest versiongatsby-plugin-alias-imports
pluginuseNavigate hook
Breaking Changes
Upgrading Gatsby, React & other dependencies
Ref: https://www.gatsbyjs.com/docs/reference/release-notes/migrating-from-v4-to-v5/#updating-your-dependencies
Using
--legacy-peer-deps
with npm: Since npm 7+ enforces stricter peer dependency rules, Gatsby recommended using the--legacy-peer-deps
option during installation. This approach was taken to prevent dependency resolution errors that could arise from incompatible plugin versions.Updating Gatsby Plugins: All Gatsby-related plugins (those prefixed with
gatsby-*
) were updated to their latest versions to ensure compatibility with v5.Community Plugins: Some third-party plugins did not immediately support Gatsby v5. In these cases, Gatsby recommends using
--legacy-peer-deps
. This is because the plugin needs to update itspeerDependencies
to include the new version of Gatsby.GraphQL Changes
Sort and Aggregation
As per the RFC: Change to sort and aggregation fields API, the
sort
argument and aggregation’sfield
argument were changed from enums to nested input objects.Gatsby provides a codemod for changing the graphql queries where the sort or aggregation is used.
NOTE: The
npx gatsby-codemods@latest sort-and-aggr-graphql <filepath>
which is written in the migration guide did not work for this project. So instead, I installed the gatsby-codemod and JSCodeshift and then ran commandjscodeshift -t node_modules/gatsby-codemods/transforms/sort-and-aggr-graphql.js .
like an example provided in gatsby-codemod docs.The following examples are taken from the Gatsby migration guide:
Sort:
Aggregation:
Extending the GraphQL MDX nodes
gatsby-plugin-mdx
to the latest version.gatsby-plugin-mdx
plugin is described in the Changes related to MDX files section.The
fields
propertyfields
property.onCreateNode
. This is still the same.fields
property instead of directly accessing it like before.Before
After
The
fileAbsolutePath
is deprecatedfileAbsolutePath
field inside the mdx nodes is deprecated. Instead, we are required to usecontentFilePath
inside theinternal
property (internal.contentFilePath
).Changes in
childImageSharp
gatsby-image
plugin is deprecated.gatsbyImageData
resolver.fullWidth
andconstrained
Changes related to MDX files
The
gatsby-plugin-mdx
latest versiongatsby-plugin-mdx
plugin.mdxOptions
, deprecation ofdefaultLayouts
and changes in thecreatePage
action.eslint
andeslint-webpack-plugin
packages as dev dependencies. This could be because of the requirements of the plugin after the update. Note that I had to downgrade theeslint
dependency from version 9 to version 7.3 to make it work.remark-gfm
package).remark-gfm
package (possibly while rendering the tables). So, I had to downgrade this package by a version. I referred to this issue and many answers suggested doing that.MDX Syntax
<img>
won't work now, it has to be the<img />
tag.{/* */}
.<
) and left curly brace ({
) have to be escaped:\<
or\{
(or use expressions:{'<'}
,{'{'}
) - From plugin migration guide<div style="width:16em;">
. Instead, the objects should be used to do the same: <div style={{width: "16em}}>. The previous way would throw an error during the build time.Layout issue in MDX files inside the pages directory.
defaultLayout
option. So all the mdx files (only inside the pages directory) need to export a default Layout component (or wrap the whole file's content in the layout component), according to the mdx v2 syntax. A good reference for all the options in place ofdefaultLayout
: https://stackoverflow.com/a/73584154. We can explore other ways too later.Handling Images
gatsby-image
plugin has been deprecated. Instead, it is recommended to use thegatsby-plugin-image
only.GatsbyImage
component from thegatsby-plugin-image
package instead of using theImage
component from the oldgatsby-image
package. In this project, we never used theImage
component from the oldgatsby-image
package, but used theImage
component from thegrommet
. I tried using the suggested components in the https://www.gatsbyjs.com/plugins/gatsby-plugin-image/#gatsby-plugin-image documentation (theGatsbyImage
component and theStaticImage
component), but they did not work out quite well. TheStaticImage
component was not rendering and theGatsbyImage
component was rendering low-quality images.grommet
. We can explore this later.Added a new
gatsby-plugin-alias-imports
plugingatsby-plugin-alias-imports
plugins to have alias imports, now src can be accessed with "@". This was done specifically to make importing layout in mdx files inside the pages directory easy. But we can add other aliases too and use them throughout the project.Removal of
useNavigate hook
useNavigate
hook from@gatsbyjs/reach-router
is removed in v5.navigate
fromgatsby
is used.