Skip to content
Latchkey

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.

next build
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.

Terminal
# 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 build

Common 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

  1. Download the font files and commit them to the repo.
  2. Switch from next/font/google to next/font/local pointing at those files.
  3. Re-run next build so no network fetch is needed.
app/layout.tsx
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-node and in engines. A bundler that resolves native bindings will pick a different prebuilt binary across majors.
  • Delete node_modules locally and reinstall from the lockfile before concluding the runner is at fault; most "works locally" reports are stale local state.
  • Set CI=true locally 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-size or 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.

Frequently asked questions

What causes Next.js "Failed to fetch next/font ... google Fonts" in CI?
There are 2 common causes: the runner cannot reach google fonts and a transient network failure during the fetch. A proxy, firewall, or air-gapped environment blocks the outbound request next/font makes at build time.
How do I fix Next.js "Failed to fetch next/font ... google Fonts" in CI?
There are 2 fixes depending on which cause you have: self-host the font with next/font/local and allow the fonts host through the proxy. Work through them in order, since the first is the most common.
What does Next.js "Failed to fetch next/font ... google Fonts" in CI actually mean?
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.
How do I stop Next.js "Failed to fetch next/font ... google Fonts" in CI happening again?
Self-host fonts with next/font/local for offline or locked-down CI. The prevention section lists 3 changes that keep it from recurring.

Related guides

References

Not every red build is your code. Latchkey repairs the ones that are not, on the runner. Start free → 30-day trial · No credit card