I’m running NextJS 14. During development (npm run dev) everything works ok.
However when I perform npm run build, I got the following error:
TypeError: fetch failed
at Object.fetch (node:internal/deps/undici/undici:11730:11)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async i (C:devnext14.nextserverappadminchecklistpage.js:1:6403)
at async n (C:devnext14.nextserverappadminchecklistpage.js:1:6569) {
cause: AggregateError
at internalConnectMultiple (node:net:1114:18)
at afterConnectMultiple (node:net:1667:5)
at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17) {
code: 'ECONNREFUSED',
[errors]: [ [Error], [Error] ]
},
digest: '2212964062'
}
Error occurred prerendering page "/admin/checklist". Read more: https://nextjs.org/docs/messages/prerender-error
TypeError: fetch failed
at Object.fetch (node:internal/deps/undici/undici:11730:11)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async i (C:devnext14.nextserverappadminchecklistpage.js:1:6403)
at async n (C:devnext14.nextserverappadminchecklistpage.js:1:6569)
✓ Generating static pages (16/16)
> Export encountered errors on following paths:
/admin/checklist/page: /admin/checklist
The admin/checklist/page is as below.
I have another page that is using the exact same function getCategories(), and they work fine. Only when I delete this page (admin/checklist/page) then the npm run build is successful.
import React from 'react'
import { jsonHeaders } from '@/lib/const'
async function getCategories() {
const res = await fetch(`${process.env.API_URL}/api/user/category`,
{
headers: jsonHeaders,
})
if (!res.ok) {
throw new Error('Failed to fetch data')
}
return res.json()
}
const AdminChecklist = async () => {
const data = await getCategories()
return (
<div>AdminChecklist</div>
)
}
export default AdminChecklist