Next.js "Failed to fetch `next/font` ... Google Fonts" in CI
next/font/google downloads and self-hosts the font files at build time. If the runner cannot reach fonts.googleapis.com (offline, proxy, or transient failure), the build throws and stops.
What this error means
next build fails with "Failed to fetch Inter from Google Fonts" and a fetch or network error, usually on locked-down or air-gapped CI, or intermittently on a flaky network.
Failed to compile.
./app/layout.tsx
`next/font` error:
Failed to fetch `Inter` from Google Fonts.Diagnose it: is it resolution, transform, or memory?
Bundler failures in CI fall into three families and the error text often points at the wrong one. A module that resolves on your machine and not on the runner is nearly always case sensitivity or a missing optional dependency; a transform error is a config or version mismatch; and an unexplained kill with no stack is the out-of-memory reaper, not a build error at all.
# 1. resolution: does the file exist with EXACTLY that case?
git ls-files | grep -i "the/imported/path"
# 2. transform: what versions is CI actually resolving?
npm ls webpack vite rollup esbuild typescript 2>/dev/null | head -20
# 3. memory: was it killed rather than failed?
# exit 137 = SIGKILL (OOM). Nothing in the bundler log will explain it.
node --max-old-space-size=4096 node_modules/.bin/vite buildCommon causes
The runner cannot reach Google Fonts
A proxy, firewall, or air-gapped environment blocks the outbound request next/font makes at build time.
A transient network failure during the fetch
A momentary DNS or connection error makes the one-shot font download fail and abort the build.
How to fix it
Self-host the font with next/font/local
- Download the font files and commit them to the repo.
- Switch from next/font/google to next/font/local pointing at those files.
- Re-run next build so no network fetch is needed.
import localFont from 'next/font/local'
const inter = localFont({ src: './Inter.woff2' })Allow the fonts host through the proxy
If you keep next/font/google, ensure the runner can reach fonts.googleapis.com and fonts.gstatic.com.
Make the build reproducible before you debug it
- Pin the Node major in
setup-nodeand inengines. A bundler that resolves native bindings will pick a different prebuilt binary across majors. - Delete
node_moduleslocally and reinstall from the lockfile before concluding the runner is at fault; most "works locally" reports are stale local state. - Set
CI=truelocally to reproduce. Several toolchains change behaviour under it, including treating warnings as errors. - Exit code 137 is an out-of-memory kill. Raise
--max-old-space-sizeor move to a larger runner rather than searching the bundler config.
How to prevent it
- Self-host fonts with next/font/local for offline or locked-down CI.
- Allowlist Google Fonts hosts where build-time fetching is required.
- Retry the build on transient network errors.