Removing gatsby clean from the build process on a Gatsby site with Netlify CMS

I am currently running a Gatsby site with NetlifyCMS and have been looking for a workaround so I don’t have to run gatsby clean every time after changes have been made in the CMS => meaning removing the gatsby clean command from the build command.

If I don’t gatsby clean, the build crashes when I change any markdown content.

Because of the large number of images on my site, having to rebuild every time from scratch takes a lot longer than it should.

The problem seems to be that images cannot be found after changes have been made to the md file resulting in “Cannot read property ‘childImageSharp’ of null”. So far only removing the cache and public folder seems to resolve the issue, but this comes with long build times.

Even the gatsby-netlify-cms-starter uses the gatsby clean command before running npm build.

Any possible workaround for this?

Hi @banx,
A few questions to try and pinpoint the issue:

  • Does the build error happening both on Netlify and locally?
  • Does it happen when running in development mode?
  • Does it happen when you edit a markdown manually or only when using the CMS?
  • Does it happen for all markdown files or for a specific file?
  • Which versions of Node, Gatsby and the CMS plugin are you using? I recommend updating to the latest ones.
  • Are you using npm or yarn? I’ve seen cases with Gatsby that switching to yarn fixes such issues.
  • Can you share a repo with the issue?

Regardless, when working with images and Gatsby I also recommend referencing images relativity to the content via Beta Features! | Netlify CMS | Open-Source Content Management System as Gatsby works better with relative paths.