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.
Error: Export encountered errors on following paths:
/product/[id]: /product/42
/blog/[slug]: /blog/hello-world
> Build error occurredCommon 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
- Move browser APIs into effects, or guard with a typeof check.
useEffect(() => {
const w = window.innerWidth;
}, []);Make build-time fetches robust
- Handle non-OK responses and return safe fallbacks so the render does not throw.
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.