Random Build Failures on Netlify while Fetching Data from DatoCMS


I am working on a static Next.js 13 project built and deployed on Netlify.

The Netlify build randomly fails when retrieving data from DatoCMS. The failures occur in different requests, making it difficult to pinpoint the exact cause.

Here’s an example from the build log:

9:37:06 PM: Error: Failed request {query:query ArticlePageBySlug($slug: String!) { ...}
9:37:06 PM:     at /opt/build/repo/.next/server/chunks/325.js:39667:15
9:37:06 PM:     at processTicksAndRejections (node:internal/process/task_queues:96:5)
9:37:06 PM:     at async Page (/opt/build/repo/.next/server/app/indhold/[slug]/page.js:445:44)

For my request mechanism, I utilized the approach from the DatoCMS sample project “next-minimalistic-photography.”

What can be the reason for this? And what can I do to prevent this from happening?

I would greatly appreciate any help or suggestions.

Hello @lars

Can you run the project in a development environment (locally) and get further information on the failed request? Maybe wrapping it in a try catch block and console logging the error/response from the API? Without the error response returned by us it would be very difficult to narrow down the issue on our end

Hi @m.finamor,

I can add debug logging to the request function to see if it provides any useful information. However, the main issue is that the problem occurs randomly, and I have only experienced it once on my local system. On Netlify, the build failure rate is between 10% and 20%

Added a try-catch around request in (lib/dato.ts line 59), and got this error:

Generating static pages (77/476)Failed to set fetch cache https://graphql.datocms.com/ TypeError: terminated
    at Fetch.onAborted (node:internal/deps/undici/undici:11442:53)
    at Fetch.emit (node:events:514:28)
    at Fetch.emit (node:domain:489:12)
    at Fetch.terminate (node:internal/deps/undici/undici:10695:14)
    at Object.onError (node:internal/deps/undici/undici:11537:36)
    at Request.onError (node:internal/deps/undici/undici:8310:31)
    at errorRequest (node:internal/deps/undici/undici:10378:17)
    at Socket.onSocketClose (node:internal/deps/undici/undici:9811:9)
    at Socket.emit (node:events:514:28)
    at Socket.emit (node:domain:489:12) {
  [cause]: Error: write EPIPE
      at WriteWrap.onWriteComplete [as oncomplete] (node:internal/stream_base_commons:94:16)
      at WriteWrap.callbackTrampoline (node:internal/async_hooks:130:17)

Hello @lars thank you, this seems to be an issue with netlify we are investigating at the moment, can you attempt to deploy de demo on vercel and see if the issue persists?

Let us know!

Hi @m.finamor , and thank you for the update.

I will try making a Vercel deployment later today or tomorrow and return with my findings.

@m.finamor I Didn’t try the deployment to Vercel but did some more debugging.

It seems to be related to a NextJS 13 bug (https://github.com/vercel/next.js/issues/53695). Following some of the advice in the comments made the build work stable again.

So what I did:
Updated NodeJS version used on Netlify to 18.17.1 and downgraded NextJS to version 13.4.12. There haven’t been any problems with the build against DatoCMS endpoint since.

Thank you for taking the time to help debug the problem.

1 Like