nextjs build_error ai_generated true

Error: Export encountered errors on following pages: generating static pages exceeded timeout

ID: nextjs/too-many-static-pages

Also available as: JSON · Markdown
85%Fix Rate
87%Confidence
80Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
14 active

Root Cause

This error occurs during next build or next export when static page generation takes too long, typically because generateStaticParams() returns thousands of parameter combinations, individual page renders are slow (heavy data fetching, large computations), or the build environment has limited resources (CI/CD runners, low-memory containers). On Linux, this is exacerbated by default memory limits in Docker containers and CI environments. The timeout applies to both the overall export process and individual page generation. Fix by reducing the number of statically generated pages, optimizing page render time, increasing build resources, or using Incremental Static Regeneration instead of full static export.

generic

Workarounds

  1. 90% success Reduce statically generated pages and use on-demand rendering for the long tail
    Instead of statically generating all pages, generate only the most-visited subset and let the rest be rendered on demand: // app/blog/[slug]/page.tsx
    export async function generateStaticParams() {
      // Only pre-generate top 200 posts (by traffic)
      const topPosts = await db.posts.findMany({
        orderBy: { views: 'desc' },
        take: 200,
        select: { slug: true },
      });
      return topPosts.map(p => ({ slug: p.slug }));
    }
    
    // Allow dynamic rendering for non-pre-generated paths:
    export const dynamicParams = true;
    
    Note: this requires server-side rendering (not compatible with output: 'export'). For static export, paginate the content across multiple routes with fewer pages each
  2. 88% success Optimize individual page render time by caching data fetches and reducing computation
    Reduce per-page render time to decrease overall build time: 1) Cache shared data fetches using Next.js fetch cache: const data = await fetch(url, { next: { revalidate: 3600 } }); 2) Use React cache() for deduplication: import { cache } from 'react'; const getConfig = cache(async () => await fetchConfig()); 3) Move heavy computations to build-time scripts: generate JSON data files during CI before next build, then import them statically. 4) Optimize images at build time instead of during render. 5) Set staticPageGenerationTimeout in next.config.js to a reasonable value (default is 60s): module.exports = { staticPageGenerationTimeout: 120 };
  3. 87% success Use Incremental Static Regeneration (ISR) instead of full static export for large sites
    Replace output: 'export' with ISR to generate pages on demand and cache them: // Remove output: 'export' from next.config.js
    // In your page:
    export const revalidate = 3600; // Revalidate every hour
    
    export async function generateStaticParams() {
      // Generate only critical pages at build time
      return [{ slug: 'about' }, { slug: 'contact' }];
    }
    
    // All other pages are generated on first request and cached
    export const dynamicParams = true;
    
    Deploy to a platform supporting ISR (Vercel, self-hosted with Node.js server). For Docker: use output: 'standalone' and run the Next.js server. ISR spreads the generation cost over time instead of concentrating it at build time

Dead Ends

Common approaches that don't work:

  1. Increasing the Node.js --max-old-space-size to fix the timeout 80% fail

    The static generation timeout is time-based, not memory-based. Increasing the heap size only helps if the timeout is caused by garbage collection pauses, which is rare. Most timeout issues are caused by slow data fetching during page rendering, excessive page count, or CPU-bound rendering. Increasing memory without addressing the root cause (slow renders or too many pages) does not help and may actually slow down builds due to GC overhead on oversized heaps

  2. Setting staticPageGenerationTimeout to an extremely high value (e.g., 600+ seconds) 70% fail

    While Next.js allows configuring staticPageGenerationTimeout in next.config.js, setting it very high masks the underlying performance problem. CI/CD pipelines have their own timeouts (typically 10-30 minutes for a build step), and individual page renders taking minutes indicate a fundamental issue with data fetching or rendering logic. The build will still be impractically slow even if it eventually completes

  3. Parallelizing static generation by running multiple build processes concurrently 90% fail

    Next.js already parallelizes static generation internally using worker threads. Running multiple next build processes concurrently on the same project causes file system conflicts, corrupted build output, and race conditions in the .next directory. Additionally, multiple processes competing for the same CPU and memory resources will likely make each individual build slower rather than faster

Error Chain

Leads to:
Preceded by:
Frequently confused with: