nextjs build_error ai_generated true

Error: Static generation timed out after 60 seconds for path '/[slug]'. Consider increasing the static generation timeout in next.config.js.

ID: nextjs/static-generation-timeout-path

Also available as: JSON · Markdown · 中文
80%Fix Rate
87%Confidence
1Evidence
2024-03-05First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
Next.js 14.0.0 active
Next.js 15.0.0 active

Root Cause

A page using generateStaticParams or static generation (output: 'export' or dynamicParams: false) took longer than the default 60-second timeout to generate all static pages. This is often due to slow data fetching or too many dynamic routes.

generic

中文

使用 generateStaticParams 或静态生成(output: 'export' 或 dynamicParams: false)的页面生成所有静态页面耗时超过默认的 60 秒超时。这通常是由于数据获取缓慢或动态路由过多。

Official Documentation

https://nextjs.org/docs/app/api-reference/next-config-js/staticGenerationTimeout

Workarounds

  1. 90% success Increase the static generation timeout in next.config.js using the experimental.staticGenerationTimeout option.
    Increase the static generation timeout in next.config.js using the experimental.staticGenerationTimeout option.
  2. 85% success Optimize generateStaticParams to fetch data more efficiently. Use batch fetching, caching, or limit the number of paths returned.
    Optimize generateStaticParams to fetch data more efficiently. Use batch fetching, caching, or limit the number of paths returned.
  3. 75% success If using output: 'export', consider switching to partial prerendering or ISR for pages with many dynamic routes. Alternatively, use a custom build script to generate pages in batches.
    If using output: 'export', consider switching to partial prerendering or ISR for pages with many dynamic routes. Alternatively, use a custom build script to generate pages in batches.

中文步骤

  1. 在 next.config.js 中使用 experimental.staticGenerationTimeout 选项增加静态生成超时时间。
  2. 优化 generateStaticParams 以更高效地获取数据。使用批量获取、缓存或限制返回的路径数量。
  3. 如果使用 output: 'export',考虑对具有许多动态路由的页面切换到部分预渲染或 ISR。或者,使用自定义构建脚本分批生成页面。

Dead Ends

Common approaches that don't work:

  1. Setting dynamicParams: true in the page segment config to allow dynamic rendering for missed routes. 60% fail

    This only affects runtime behavior for ungenerated routes, not the static generation timeout itself; the timeout still applies to the initial build.

  2. Removing generateStaticParams entirely to let Next.js handle all routes dynamically. 70% fail

    This changes the page to dynamic rendering, which may not be desired for SEO or performance; also, if output: 'export' is set, this will cause a build error.

  3. Adding revalidate to the page's fetch calls to enable ISR, thinking it bypasses static generation timeout. 50% fail

    ISR still requires initial static generation; the timeout applies to the first build, not runtime revalidation.