Gatsby JS build fails: Build failed due to a user error: Build script returned non-zero exit code: 2

Until just now we’ve been using Gatsby Cloud to build our Gatsby JS site which then deploys to Netlify. However, with the recent decision to move Gatsby Cloud into Netlify, we’re now in a position where the build fails every time.

It builds without issue on Gatsby Cloud. The same repository fails to build on Netlify with an error of:

Build failed due to a user error: Build script returned non-zero exit code: 2

For context, we use Prismic as the CMS and the site is currently on Gatsby v2 (it’s not possible to upgrade at the moment).

We have a staging version of Prismic and a live version of Prismic. The site builds fine when using the data from the staging version of Prismic but fails on the live version.

I wonder if you could please help me figure out why the site is failing each time when using the live CMS data?

The site is called: ‘leafy-torrone-d97831’. Below is the deploy log. My thoughts are that because the live site has more pages, images etc that it’s timing out or using too much memory. Would upgrading resolve this issue?

The build is failing at:

Whatever you’re doing in there seems to be taking more than 8 GB RAM that Starter users get. Unlike on Gatsby Cloud, RAM annot be configured. On Pro you get 11 GB RAM though, so if you need just a little boost, that might be an option to consider. But if you need more than that, you might be to build locally and deploy via CLI.