November 25, 2020     2 min read

Keeping GatsbyJS Projects Healthy

Keeping GatsbyJS Projects Healthy

In this brief post we cover what it takes to keep your GatsbyJS projects up to date and functioning whilst also taking advantages of more recent features.

GatsbyJS Dependency Updates

GatsbyJS (and NodeJS projects for that matter) should have their dependencies updated to their most recent versions at least once a quarter. This gives you the benefit of new feature and bug fixes whilst already protecting yourself from a more difficult update of packages in the future.

To do this I make use of a tool called npm-check that I always install globally in my NodeJS environments as it's handy.

Within your GatsbyJS project install npm-check by running the following:

npm install -g npm-check

Then run the following command to interactively update any packages that might need have to also bumped.

npm-check -u
npm-check Example list of packages that have updates
npm-check Example list of packages that have updates

You'll have a long list of upgrades depending on the last time you ran this process. From experience you are okay installing updates from Patch and Minors whereas updates listed under the Major or Non-Semver you might need to be more careful with.

I have found that most of the time I can take Major and Non-Semver changes and not run into issues, but it will depend a lot of what other dependencies you work with.

Go through and install all the updates you would like, then run your normal build/serve commands to test that there are no breaking changes in your site.

npm-check Running updates
npm-check Running updates
# These commands might be slightly different for your build.
npm install
npm run develop

NOTE: If you have issues running your build after updating, sometimes it can help to clear existing cache by running the two following commands:

# The basic clean
gatsby clean

# A full clean ONLY do this if the first doesn't work
rm -rf node_modules && rm package-lock.json && npm install

Conclusion

Just a short one today, but an important simple process you can run regularly if you get bored and want to update your projects so you aren't falling too far behind.

Please reach out to me on Twitter if you have any further queries or if you have other ways of dealing with this process!

devopstar

DevOpStar by Nathan Glover | 2024