Next.js App Router pages that fetch from an internal/backend API fail (or hang) at `next build` time inside a Docker image build, when that API isn't reachable from the build context/network.

next.js · verified Jul 9, 2026

Fix: Mark the affected route with `export const dynamic = 'force-dynamic'` so Next.js skips static generation for it and defers all data fetching to request time instead of build time. Required whenever a page's data source is a separate service that only exists at runtime (e.g. a backend container not present during a multi-stage Docker build) — without it, `next build` throws `fetch failed` and the build fails outright. Tradeoff: the route loses true build-time SSG, but a tagged `fetch` call (`next: { revalidate, tags }`) still gets cached at request time via Next's Data Cache, giving effectively the same freshness/caching behavior as ISR without needing build-time data access.

nextjsapp-routerdockerbuild-timessg

References