Im getting this error when I try to deploy an app using Nextjs / TS / Sanity to Vercel
18:39:44.458] Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
[18:39:44.458] TypeError: fetch failed
[18:39:44.458] at Object.fetch (node:internal/deps/undici/undici:14062:11)
[18:39:44.459] at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
[18:39:44.459] at async fetchPageInfo (/vercel/path0/.next/server/pages/index.js:1176:17)
[18:39:44.459] at async getStaticProps (/vercel/path0/.next/server/pages/index.js:1037:22)
[18:39:44.460] at async renderToHTML (/vercel/path0/node_modules/next/dist/server/render.js:389:20)
[18:39:44.460] at async /vercel/path0/node_modules/next/dist/export/worker.js:354:36
[18:39:44.460] at async Span.traceAsyncFn (/vercel/path0/node_modules/next/dist/trace/trace.js:79:20)
[18:39:44.461] info - Generating static pages (3/3)
[18:39:44.464]
[18:39:44.464] > Build error occurred
[18:39:44.465] Error: Export encountered errors on following paths:
[18:39:44.466] /
[18:39:44.466] at /vercel/path0/node_modules/next/dist/export/index.js:425:19
[18:39:44.466] at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
[18:39:44.466] at async Span.traceAsyncFn (/vercel/path0/node_modules/next/dist/trace/trace.js:79:20)
[18:39:44.466] at async /vercel/path0/node_modules/next/dist/build/index.js:1422:21
[18:39:44.467] at async Span.traceAsyncFn (/vercel/path0/node_modules/next/dist/trace/trace.js:79:20)
[18:39:44.467] at async /vercel/path0/node_modules/next/dist/build/index.js:1280:17
[18:39:44.467] at async Span.traceAsyncFn (/vercel/path0/node_modules/next/dist/trace/trace.js:79:20)
[18:39:44.467] at async Object.build [as default] (/vercel/path0/node_modules/next/dist/build/index.js:73:29)
[18:39:44.517] Error: Command "npm run build" exited with 1
The error comes from this:
export const fetchPageInfo = async () => {
const res = await fetch (`${process.env.NEXT_PUBLIC_BASE_URL}/api/getPageInfo`)
process
const data = await res.json()
const pageInfo: PageInfo = data.pageInfo
//console.log(pageInfo)
return pageInfo
}
When I run it locally there is no issue, the value of this variable NEXT_PUBLIC_BASE_URL is https://localhost:3000 so I thought, of course it won't work during the building process, it's trying to fetch info from that url.
So with a very basic trial and error I deploy the app w/o all the queries and the components which use that data and it worked, even tried the endpoints of the API and they also worked. So then I updated the app adding all the queries and the components again but with value of NEXT_PUBLIC_BASE_URL being the url of the deploy app, even I tryed to deploy another instance of the up but I keep getting the same error.