I’m seeing this same error frequently (but not every time) on my builds and have been ever since we upgraded from Gatsby 3 to Gatsby 4. The link above was closed with the implication it was due to a problem with gatsby-remark-images-contentful, but I’m not using that package.
Hello! I’m delighted to say we have a fix for this. It turns out it was not a memory issue after all, but was a bug in Gatsby. It doesn’t appear when building locally because most people are using multi-core machines and the bug only appears when using a single worker. We worked with the Gatsby team to release a fix which went out today. If you update your site to firstname.lastname@example.org then it should fix the problem.