Can't understand why my Gatsby Build fails: Build script returned non-zero exit code: 2

Hi guys, i can’t figured out why my gatsby build continue to fail.

This is my site name: yplatform-staging
buildId: 650c4237adaaa12d3449729b
deployId: 650c4237adaaa12d3449729d

This is the build error that i receive

3:56:15 PM: ────────────────────────────────────────────────────────────────
3:56:15 PM: ​
3:56:15 PM:   Error message
3:56:15 PM:   Command failed with exit code 1: CI= npm run build (https://ntl.fyi/exit-code-1)
3:56:15 PM: ​
3:56:15 PM:   Error location
3:56:15 PM:   In Build command from Netlify app:
3:56:15 PM:   CI= npm run build
3:56:15 PM: ​
3:56:15 PM:   Resolved config
3:56:15 PM:   build:
3:56:15 PM:     base: /opt/build/repo/landing
3:56:15 PM:     command: CI= npm run build
3:56:15 PM:     commandOrigin: ui
3:56:15 PM:     environment:
3:56:15 PM:       - AVAILABLE_LANGUAGES
3:56:15 PM:       - CI
3:56:15 PM:       - COOKIE_API_KEY
3:56:15 PM:       - COOKIE_DOMAIN
3:56:15 PM:       - COOKIE_POLICY_ID
3:56:15 PM:       - COOKIE_SITE_ID
3:56:15 PM:       - CRAWL_URL
3:56:15 PM:       - DEFAULT_LANGUAGE
3:56:15 PM:       - GATSBY_ACTIVE_ENV
3:56:15 PM:       - GATSBY_BRAZE_GCF_SHARED_SECRET
3:56:15 PM:       - GATSBY_BRAZE_GCF_URL
3:56:15 PM:       - GATSBY_CONNECTION_TIMEOUT
3:56:15 PM:       - GATSBY_EDUCATION_URL
3:56:15 PM:       - GATSBY_STALL_RETRY_LIMIT
3:56:15 PM:       - GATSBY_STALL_TIMEOUT
3:56:15 PM:       - NODE_ENV
3:56:15 PM:       - NODE_VERSION
3:56:15 PM:       - NPM_TOKEN
3:56:15 PM:       - SETUP_BACKEND_TEST_URL
3:56:15 PM:       - SETUP_BACKEND_URL
3:56:15 PM:       - SETUP_SOCKET_URL
3:56:15 PM:       - WORDPRESS_BLOG_URL
3:56:15 PM:     publish: /opt/build/repo/landing/public
3:56:15 PM:     publishOrigin: ui
3:56:15 PM:   functionsDirectory: /opt/build/repo/landing/src/api
3:56:15 PM:   plugins:
3:56:15 PM:     - inputs: {}
3:56:15 PM:       origin: ui
3:56:15 PM:       package: '@netlify/plugin-gatsby'
3:57:35 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
3:57:35 PM: Failing build: Failed to build site
3:57:36 PM: Finished processing build request in 40m54.827s

Theese are my deplo config


u

Hi @o.deangelis,

Thanks for reaching out and welcome to Netlify’s Support Forums!

Looks like the error is here:

contentNodes

The second error is providing debugging tips:

error gatsby-source-wordpress Request failed with status code 500

10:38:28 AM: Your WordPress server is either overloaded or encountered a PHP error.

10:38:28 AM: Error occurred while fetching nodes of the Category type.

10:38:28 AM: Enable WordPress debugging by adding the following to your wp-config.php file:

10:38:28 AM: define(WP_DEBUG, true);

10:38:28 AM: define(WP_DEBUG_LOG, true);

10:38:28 AM: define(GRAPHQL_DEBUG, true);

10:38:28 AM: (See https://wordpress.org/support/article/debugging-in-wordpress/ for more info)

10:38:28 AM: Then run another build before checking your WordPress instance's debug.log file for errors.

10:38:28 AM: If you don't see any errors in debug.log:

10:38:28 AM: Try reducing the requestConcurrency for content updates or the previewRequestConcurrency for previews, and/or reducing the schema.perPage option:

Could you try the suggested debuggging tips to see if you’re able to resolve the issue?

Hi Melvin, thanks for your help but what you are posting is not the right build, you are looking at 10:38 AM Logs, what i’ve pasted was at 3.56PM.
The only error that i get is the one the i pasted and the one that i see using the deploy id: 650c4237adaaa12d3449729d.

I really can’t figured out what was not working cause the builds fail after

3:50:12 PM: success Building production JavaScript and CSS bundles - 83.636s
3:50:46 PM: success Building HTML renderer - 33.706s
3:50:46 PM: success Execute page configs - 0.157s
3:50:46 PM: success Caching Webpack compilations - 0.001s

Hi @o.deangelis,

The timing of the logs have nothing to do with this. It’s just a timezone difference. The same logs show a different time for me as we’re all in different time zones.

As far as the error is concerned, @Melvin is right and this is something you’d have to debug on your end. Your WordPress server is responding with an error 500:

and that’s not something we can help with.

I think we are probably seen 2 different builds, couse the error that you show is the one of the last failed build, not the one that i’m pasting you here.

On this builds:
3:17:40 PM: buildId: 650c4237adaaa12d3449729b
3:17:40 PM: deployId: 650c4237adaaa12d3449729d

3:18:24 PM: success  gatsby-source-wordpress  WpLegalCategory - 2.905s - fetched 12
3:18:28 PM: success  gatsby-source-wordpress  Temi - 6.371s - fetched 15
3:18:30 PM: success  gatsby-source-wordpress  LegalDocs - 8.558s - fetched 62
3:18:34 PM: success  gatsby-source-wordpress  WpAboutGroup - 3.494s - fetched 15
3:18:36 PM: success  gatsby-source-wordpress  WpArgomento - 6.355s - fetched 15
3:18:39 PM: success  gatsby-source-wordpress  WpAboutUs - 9.225s - fetched 60
3:18:40 PM: success  gatsby-source-wordpress  WpfaqTag - 9.905s - fetched 58
3:18:58 PM: success  gatsby-source-wordpress  WpFaq - 28.259s - fetched 306
3:19:00 PM: success  gatsby-source-wordpress  Comment - 1.184s - fetched 0
3:19:06 PM: success  gatsby-source-wordpress  ContentType - 7.234s - fetched 10
3:19:23 PM: success  gatsby-source-wordpress  Category - 24.762s - fetched 15
3:19:26 PM: success  gatsby-source-wordpress  WpToken - 27.836s - fetched 237
3:19:46 PM: success  gatsby-source-wordpress  WpGlossary - 47.749s - fetched 541
3:19:47 PM: success  gatsby-source-wordpress  Taxonomy - 0.894s - fetched 8
3:19:47 PM: success  gatsby-source-wordpress  PostFormat - 1.109s - fetched 6
3:19:54 PM: success  gatsby-source-wordpress  Tag - 8.191s - fetched 29
3:22:48 PM: success  gatsby-source-wordpress  Post - 182.042s - fetched 1692
3:22:49 PM: success  gatsby-source-wordpress  UserRole - 0.672s - fetched 0
3:22:49 PM: success  gatsby-source-wordpress  User - 1.297s - fetched 13
3:47:30 PM: success  gatsby-source-wordpress  MediaItem - 1480.826s - fetched 2354
3:47:30 PM: success  gatsby-source-wordpress  creating nodes - 1480.828s
3:47:30 PM: success  gatsby-source-wordpress  fetching nodes - 1748.742s - 5448 total
3:47:30 PM: success Downloading remote files - 1479.469s - 1461/1461 0.99/s
3:47:34 PM: success Checking for changed pages - 0.000s
3:47:34 PM: success source and transform nodes - 1763.158s
3:47:39 PM: info Writing GraphQL type definitions to /opt/build/repo/landing/.cache/schema.gql
3:47:40 PM: success building schema - 6.096s
3:47:52 PM: success createPages - 11.230s
3:47:52 PM: success createPagesStatefully - 0.144s
3:47:52 PM: info Total nodes: 12122, SitePage nodes: 3359 (use --verbose for breakdown)
3:47:52 PM: success Checking for changed pages - 0.001s
3:47:52 PM: success onPreExtractQueries - 0.001s
3:47:56 PM: success  gatsby-source-wordpress  diff schemas - 2.111s
3:47:56 PM: success  gatsby-source-wordpress  ingest WPGraphQL schema - 2.111s
3:48:31 PM: success extract queries from components - 39.205s

The Wordpress data fetching is successfull.
The builds fails after this steps

3:50:12 PM: success Building production JavaScript and CSS bundles - 83.636s
3:50:46 PM: success Building HTML renderer - 33.706s
3:50:46 PM: success Execute page configs - 0.157s
3:50:46 PM: success Caching Webpack compilations - 0.001s
3:56:15 PM: ​
3:56:15 PM:   Error message
3:56:15 PM:   Command failed with exit code 1: CI= npm run build (https://ntl.fyi/exit-code-1)
3:56:15 PM: ​
3:56:15 PM:   Error location
3:56:15 PM:   In Build command from Netlify app:
3:56:15 PM:   CI= npm run build
3:56:15 PM: ​
3:56:15 PM:   Resolved config
3:56:15 PM:   build:
3:56:15 PM:     base: /opt/build/repo/landing
3:56:15 PM:     command: CI= npm run build
3:56:15 PM:     commandOrigin: ui
3:56:15 PM:     environment:
3:56:15 PM:       - AVAILABLE_LANGUAGES
3:56:15 PM:       - CI
3:56:15 PM:       - COOKIE_API_KEY
3:56:15 PM:       - COOKIE_DOMAIN
3:56:15 PM:       - COOKIE_POLICY_ID
3:56:15 PM:       - COOKIE_SITE_ID
3:56:15 PM:       - CRAWL_URL
3:56:15 PM:       - DEFAULT_LANGUAGE
3:56:15 PM:       - GATSBY_ACTIVE_ENV
3:56:15 PM:       - GATSBY_BRAZE_GCF_SHARED_SECRET
3:56:15 PM:       - GATSBY_BRAZE_GCF_URL
3:56:15 PM:       - GATSBY_CONNECTION_TIMEOUT
3:56:15 PM:       - GATSBY_EDUCATION_URL
3:56:15 PM:       - GATSBY_STALL_RETRY_LIMIT
3:56:15 PM:       - GATSBY_STALL_TIMEOUT
3:56:15 PM:       - NODE_ENV
3:56:15 PM:       - NODE_VERSION
3:56:15 PM:       - NPM_TOKEN
3:56:15 PM:       - SETUP_BACKEND_TEST_URL
3:56:15 PM:       - SETUP_BACKEND_URL
3:56:15 PM:       - SETUP_SOCKET_URL
3:56:15 PM:       - WORDPRESS_BLOG_URL
3:56:15 PM:     publish: /opt/build/repo/landing/public
3:56:15 PM:     publishOrigin: ui
3:56:15 PM:   functionsDirectory: /opt/build/repo/landing/src/api
3:56:15 PM:   plugins:
3:56:15 PM:     - inputs: {}
3:56:15 PM:       origin: ui
3:56:15 PM:       package: '@netlify/plugin-gatsby'
3:57:35 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
3:57:35 PM: Failing build: Failed to build site
3:57:36 PM: Finished processing build request in 40m54.827s

So - what is the next step in your local build (which I’m sure you’ve tested and works, right?)? You should be able to tell that from your local build logs, and then you can review what it is doing, or add more debugging to that step, so it will show you what happened :wink:

On my local machine all works man, and on Gatsby Cloud the sites actually builds, i’ve got this issue only building on neltify and i do not receive any help error.

Hi @o.deangelis

Your build is failing because you are running out of memory:

Please take a look at this article for troubleshooting steps: [Support Guide] What can I do if my build fails for memory-overallocation-related errors?

I hope this helps!

1 Like

Thank you @elden, nice hint :innocent:

I’ve tried to set the flags in the NODE_ENV = max-old-space-size and set to 8192 and 16384 too, but this does not solve the issue.

Now i’m going to upgrade Gatsby to a new major version cause i think (hope) this should have a good impact on performance side, but my question is why on my local machine and neither on Gatsby Cloud i’ve never had this issue ?

HI @o.deangelis

I think we’re just looking at a difference in the available memory on the different environments. On your local machine, you have all of your local system’s resources for your build. I don’t know what resources are specifically assigned to a build on Gatsby Cloud but I think we can be pretty sure it’s not the same as Netlify. On Netlify, since you are on a starter account, you are guaranteed 8GBytes of memory and 4 CPUs.

If you want to know more about what resources are available to you based on your plan, check out this support guide:

And for our best tips on how to troubleshoot, check out that support guide I linked in my last post ( What can I do if my build fails for memory-overallocation-related errors? )

I hope this helps!

Thanks for your answer @elden !
On a pro account the memory is still 8GB, cause i’m building this site on my company account that uses a pro account ?

In that case, where can i find this info ? Cause on the pricing section i can’t find any info about the gauranteed memory resource per plan ?

Hi @o.deangelis

On a Pro account, the memory allocation should be 11GB. If you look at the chart I posted for you previously, you’ll see that you are still hitting that 11GB limit in your build.

The info on what resources are allocated to your build environment is not on the pricing page. That info can be found here: [Support Guide] Making sure your builds use appropriate resources for Netlify's build system. The information in that support guide is up to date and we modify it when the build environment changes.

Okey man thank you again <3
I’m trying to contact the Netlify team for the Enterprise plan, to get more memory allocation, but no one already an answer me :frowning:

Hi @o.deangelis

I just dropped a note to our sales team letting them know you wanted to speak to someone.