Next.js: Error occurred prerendering page "/blog" TypeError: fetch failed { cause: Error: connect ECONNREFUSED 127.0.0.1:3000 }
During next build a page tried to fetch data from a server (often your own app or an API) that isn't running yet.
Error occurred prerendering page "/blog". TypeError: fetch failed[cause]: Error: connect ECONNREFUSED 127.0.0.1:3000 next buildError occurred prerendering page TypeError: fetch failed ECONNREFUSEDExport encountered errors on following paths ECONNREFUSEDnext build fetch failed ECONNREFUSED Meaning
Static generation runs at build time, when localhost:3000 doesn't exist. Fetch from the real data source (DB/CMS/public API) or make the page dynamic (export const dynamic = 'force-dynamic'). In CI, start required services first or provide the environment variables.
Common causes
- Pre-render fetching
http://localhost:3000/api/... - API/CMS not reachable from the build environment
- Missing environment variables at build (URL undefined)
- Docker build without network access to the DB
- Rate limits/firewall during build
⚡ Quick fix
- Call the data function directly instead of fetching your own API
export const dynamic = "force-dynamic"to skip prerendering- Provide env vars and network access in CI
Detailed fix by platform
Next.js
export const dynamic = "force-dynamic"; // render at request time
How to diagnose
- Target — localhost or external?
- Build — Network available?
- Env — Variables set?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- _next/image 400 / upstream image response failed Next.js: ⨯ upstream image response failed for https://example.com/a.jpg 404 / url parameter is not allowed
- 'sharp' is required to be installed in standalone mode Next.js: Error: 'sharp' is required to be installed in standalone mode for the image optimization to function correctly
- [Vue warn]: Component is missing template or render function Vue: [Vue warn]: Component is missing template or render function.
Most viewed in Next.js
- NEXT_REDIRECT Next.js: Error: NEXT_REDIRECT (redirect() inside try/catch)
- server-only Next.js: You're importing a component that needs "server-only". That only works in a Server Component
- cookies() should be awaited Next.js 15: Route "/x" used `cookies().get('token')`. `cookies()` should be awaited before using its value
Other ways to find it
Where this error sits
Origin: On your device. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 5 Nov 2026