How to prevent prerender error for static page that fetches data from serverless API

I'm trying to have a static props get defined by data retrieved from an endpoint on /api/hello from a t3 app. Running next dev works just fine, but when running vercel build, I get this error:
Error occurred prerendering page "/en". Read more: https://nextjs.org/docs/messages/prerender-error
TypeError: fetch failed
at Object.processResponse (node:internal/deps/undici/undici:5536:34)
at node:internal/deps/undici/undici:5858:42
at node:internal/process/task_queues:140:7
at AsyncResource.runInAsyncScope (node:async_hooks:202:9)
at AsyncResource.runMicrotask (node:internal/process/task_queues:137:8)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
info - Generating static pages (5/5)

> Build error occurred
Error: Export encountered errors on following paths:
/: /en
at /Users/alann/code/next-ssg-edge/node_modules/.pnpm/[email protected]_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/export/index.js:404:19
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Span.traceAsyncFn
at async /Users/alann/code/next-ssg-edge/node_modules/.pnpm/[email protected]_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/build/index.js:1091:17
at async Span.traceAsyncFn
Error occurred prerendering page "/en". Read more: https://nextjs.org/docs/messages/prerender-error
TypeError: fetch failed
at Object.processResponse (node:internal/deps/undici/undici:5536:34)
at node:internal/deps/undici/undici:5858:42
at node:internal/process/task_queues:140:7
at AsyncResource.runInAsyncScope (node:async_hooks:202:9)
at AsyncResource.runMicrotask (node:internal/process/task_queues:137:8)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
info - Generating static pages (5/5)

> Build error occurred
Error: Export encountered errors on following paths:
/: /en
at /Users/alann/code/next-ssg-edge/node_modules/.pnpm/[email protected]_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/export/index.js:404:19
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Span.traceAsyncFn
at async /Users/alann/code/next-ssg-edge/node_modules/.pnpm/[email protected]_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/build/index.js:1091:17
at async Span.traceAsyncFn
(cut to fit character limit) I see that fetch failed so it might just be that the env var isn't defined at the time, since I'm fetching from await fetch(http://${process.env.NEXT_PUBLIC_VERCEL_URL}/api/graphql). The thing is I already have .env.development.local defined and I see this msg: info - Loaded env from /Users/alann/code/next-ssg-edge/.env.local. Thank you.
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server