nextjs
resource_error
ai_generated
partial
错误:路径 '/[slug]' 的静态生成在 60 秒后超时。考虑增加静态生成超时时间或减少静态路径的数量。
Error: Static generation timed out after 60 seconds for path '/[slug]'. Consider increasing the static generation timeout or reducing the number of static paths.
ID: nextjs/static-generation-buffer-timeout
80%修复率
86%置信度
1证据数
2023-08-01首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 13.4.0 | active | — | — | — |
| 13.5.0 | active | — | — | — |
| 14.0.0 | active | — | — | — |
| 14.1.0 | active | — | — | — |
| 14.2.0 | active | — | — | — |
| 15.0.0 | active | — | — | — |
根因分析
Next.js 在构建期间对生成静态页面有默认的 60 秒超时。如果 generateStaticParams 返回许多路径或页面组件有慢速数据获取,构建可能会超过此限制。
English
Next.js has a default 60-second timeout for generating static pages during build. If generateStaticParams returns many paths or the page component has slow data fetching, the build may exceed this limit.
官方文档
https://nextjs.org/docs/messages/static-generation-timeout解决方案
-
Increase the static generation timeout in next.config.js: module.exports = { staticPageGenerationTimeout: 120 }; (value in seconds). This gives more time for complex builds. -
Optimize generateStaticParams by batching API calls, implementing caching, or using incremental static regeneration (ISR) with revalidate option to reduce the number of paths generated at build time. Example: export async function generateStaticParams() { const slugs = await fetch('/api/slugs?limit=100'); return slugs.map(s => ({ slug: s })); } -
Use dynamicParams: false in the page component to ensure only explicitly returned paths are pre-rendered, and fall back to dynamic rendering for others.
无效尝试
常见但无效的做法:
-
Setting generateStaticParams to return an empty array to avoid the timeout
20% 失败
This defeats the purpose of static generation; all pages will be dynamically rendered at request time, losing performance benefits.
-
Adding console.log statements inside generateStaticParams to debug, which adds overhead and makes the timeout worse
50% 失败
Logging increases I/O and slows down the generation process, potentially causing more timeouts.