nextjs build_error ai_generated true

错误:路径 '/[slug]' 的静态生成在 60 秒后超时。考虑在 next.config.js 中增加静态生成超时时间。

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

其他格式: JSON · Markdown 中文 · English
80%修复率
87%置信度
1证据数
2024-03-05首次发现

版本兼容性

版本状态引入弃用备注
Next.js 14.0.0 active
Next.js 15.0.0 active

根因分析

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

English

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

官方文档

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

解决方案

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

无效尝试

常见但无效的做法:

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

    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% 失败

    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% 失败

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