Skip to content
Latchkey

Next.js "Export encountered errors" - Fix in CI

Static export renders each page at build time. If a page throws while rendering - a runtime-only API, an undefined value, or a failing fetch - the export lists the offending paths and fails.

What this error means

The build prints Export encountered errors on following paths: followed by the routes that threw.

next
Error: Export encountered errors on following paths:
  /product/[id]: /product/42
  /blog/[slug]: /blog/hello-world

> Build error occurred

Common causes

Runtime-only code during export

A page touches window/document or a request-time API during static rendering, which has no browser or request.

Build-time data fetch failed

A getStaticProps/generateStaticParams fetch returned an error or undefined, so the page render threw.

How to fix it

Guard browser-only code

  1. Move browser APIs into effects, or guard with a typeof check.
page.tsx
useEffect(() => {
  const w = window.innerWidth;
}, []);

Make build-time fetches robust

  1. Handle non-OK responses and return safe fallbacks so the render does not throw.
getStaticProps
const res = await fetch(url);
if (!res.ok) return { notFound: true };

How to prevent it

  • Keep browser-only access out of render paths used by static export.
  • Treat build-time fetch failures as expected and handle them.

Frequently asked questions

What causes "Export errors"?
A page touches window/document or a request-time API during static rendering, which has no browser or request.
How do I fix Export errors?
Guard browser-only code

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card