NextJS build fails during generating static pages due to fetch errors

Hi!

Lately my builds started to fail. I’m deploying a nextjs project (latest version, latest netlify plugin).

Locally i can build the project fine, im using a strapi cms to get the data during build time. roughly 200 requests… not a lot. This is a full static export, so just getting the data from the CMS, building the pages, then deploy as is.

So locally it builds fine, then i can deploy it via netlify cli too. But on netlify i get weird fetch errors like during Generating static pages:

11:22:39 AM: TypeError: fetch failed
11:22:39 AM:     at Object.fetch (node:internal/deps/undici/undici:11372:11) {
11:22:39 AM:   cause: _SocketError: other side closed
11:22:39 AM:       at Socket.onSocketEnd (node:internal/deps/undici/undici:7998:26)
11:22:39 AM:       at Socket.emit (node:events:529:35)
11:22:39 AM:       at endReadableNT (node:internal/streams/readable:1368:12)
11:22:39 AM:       at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
11:22:39 AM:     code: "UND_ERR_SOCKET",
11:22:39 AM:     socket: {
11:22:39 AM:       localAddress: "::1",
11:22:39 AM:       localPort: 48700,
11:22:39 AM:       remoteAddress: undefined,
11:22:39 AM:       remotePort: undefined,
11:22:39 AM:       remoteFamily: undefined,
11:22:39 AM:       timeout: undefined,
11:22:39 AM:       bytesWritten: 1574,
11:22:39 AM:       bytesRead: 248
11:22:39 AM:     }
11:22:39 AM:   }
11:22:39 AM: }

or

11:22:53 AM: TypeError: fetch failed
11:22:53 AM:     at Object.fetch (node:internal/deps/undici/undici:11372:11)
11:22:53 AM:     at async globalThis.fetch (/opt/build/repo/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:111:13700)
11:22:53 AM:     at async invokeRequest (/opt/build/repo/node_modules/next/dist/server/lib/server-ipc/invoke-request.js:17:12)
11:22:53 AM:     at async invokeIpcMethod (/opt/build/repo/node_modules/next/dist/server/lib/server-ipc/request-utils.js:45:21)
11:22:53 AM:     at async /opt/build/repo/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:111:17891 {
11:22:53 AM:   cause: Error: read ECONNRESET
11:22:53 AM:       at TCP.onStreamRead (node:internal/stream_base_commons:217:20)
11:22:53 AM:       at TCP.callbackTrampoline (node:internal/async_hooks:130:17) {
11:22:53 AM:     errno: -104,
11:22:53 AM:     code: "ECONNRESET",
11:22:53 AM:     syscall: "read"
11:22:53 AM:   }
11:22:53 AM: }

Then the build fails. Sometimes it does run though, but its like 1 out of 10 nowadays… tried deleting the build cache too, sometimes worked… but currently it just fails

Any ideas, suggestions how can i fix this? I can see strapi side the incoming requests, the log says all good with statuscode 200.

thanks a lot

This is not something Netlify can fix. Networks can keep failing from time to time (could be us, or could be your backend, or both).

This is simply a connection reset, can happen due to either side (client or the server).

This on the other hand says that the other side closed the socket.

Maybe your backend is blocking Netlify’s IPs or something, but that’s as far as we can debug these transient network issues.

Thanks for your reply!

Well, I opened this issue, because the same configuration builds / deploys without issues on Vercel, also builds locally without issues… i thought this might be the CMS on railway, but according to the logs its all okay, handles multiple builds at the same time without issues.

When i meant without issues, 10/10 builds on Vercel. Netlify 1/10.

the api is in us-west, build happens in us-east (1)… but also happens in EU without problems…

so just kinda weird that it only happens here…

I understand, but not sure what to say. With your given explanation, this is the only possible explanation:

Hi @artanisdesign.

Have you found any solution for this? I have the same situation, expect I’m running my nextjs app on Vercel, and 90% of the time the build fails.
Same error messages. I have a WP on a different server which serves the data through wp-graphql. Maybe that is the source of the problem.

If you found anyting, please share with me. Thanks!