I build a blog website with next js but when deploying it with netlify i got this issues

7:58:57 AM: Import trace for requested module:
7:58:57 AM: ./components/section1.js
7:58:57 AM: Collecting page data …
7:58:57 AM: TypeError: fetch failed
7:58:57 AM: at Object.fetch (node:internal/deps/undici/undici:11730:11)
7:58:57 AM: at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
7:58:57 AM: at async a (/opt/build/repo/.next/server/pages/posts/[postId].js:1:7076)
7:58:57 AM: at async x (/opt/build/repo/.next/server/pages/posts/[postId].js:1:59173)
7:58:57 AM: at async buildStaticPaths (/opt/build/repo/node_modules/next/dist/build/utils.js:758:33)
7:58:57 AM: at async /opt/build/repo/node_modules/next/dist/build/utils.js:1174:110
7:58:57 AM: at async Span.traceAsyncFn (/opt/build/repo/node_modules/next/dist/trace/trace.js:140:20) {
7:58:57 AM: cause: Error: connect ECONNREFUSED ::1:3000
7:58:57 AM: at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1555:16) {
7:58:57 AM: errno: -111,
7:58:57 AM: code: “ECONNREFUSED”,
7:58:57 AM: syscall: “connect”,
7:58:57 AM: address: “::1”,
7:58:57 AM: port: 3000
7:58:57 AM: }
7:58:57 AM: }
7:58:57 AM: > Build error occurred
7:58:57 AM: Error: Failed to collect page data for /posts/[postId]
7:58:57 AM: at /opt/build/repo/node_modules/next/dist/build/utils.js:1217:15
7:58:57 AM: at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
7:58:57 AM: type: “Error”
7:58:57 AM: }
7:58:57 AM: ​
7:58:57 AM: “build.command” failed
7:58:57 AM: ────────────────────────────────────────────────────────────────
7:58:57 AM: ​
7:58:57 AM: Error message
7:58:57 AM: Command failed with exit code 1: CI=“” npm run build
7:58:57 AM: ​
7:58:57 AM: Error location
7:58:57 AM: In Build command from Netlify app:
7:58:57 AM: CI=“” npm run build
7:58:57 AM: ​
7:58:57 AM: Resolved config
7:58:57 AM: build:
7:58:57 AM: command: CI=“” npm run build
7:58:57 AM: commandOrigin: ui
7:58:57 AM: environment:
7:58:57 AM: - PORT
7:58:57 AM: - NEXT_PRIVATE_TARGET
7:58:57 AM: publish: /opt/build/repo/.next
7:58:57 AM: publishOrigin: ui
7:58:57 AM: plugins:
7:58:57 AM: - inputs: {}
7:58:57 AM: origin: ui
7:58:57 AM: package: “@netlify/plugin-nextjs”
7:58:57 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
7:58:57 AM: Failing build: Failed to build site
7:58:58 AM: Finished processing build request in 36.711s

Hi @HenryDustin , thanks for the post.

The error is happening on the quoted line above.
Looks like you are trying the fetch post data during build time.
Kindly make sure the API for fetching the posts is a valid API route.