# 错误：路径 '/[slug]' 的静态生成在 60 秒后超时。考虑增加静态生成超时时间或减少静态路径的数量。

- **ID:** `nextjs/static-generation-buffer-timeout`
- **领域:** nextjs
- **类别:** resource_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

Next.js 在构建期间对生成静态页面有默认的 60 秒超时。如果 generateStaticParams 返回许多路径或页面组件有慢速数据获取，构建可能会超过此限制。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 13.4.0 | active | — | — |
| 13.5.0 | active | — | — |
| 14.0.0 | active | — | — |
| 14.1.0 | active | — | — |
| 14.2.0 | active | — | — |
| 15.0.0 | active | — | — |

## 解决方案

1. ```
   Increase the static generation timeout in next.config.js: module.exports = { staticPageGenerationTimeout: 120 }; (value in seconds). This gives more time for complex builds.
   ```
2. ```
   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 })); }
   ```
3. ```
   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** — This defeats the purpose of static generation; all pages will be dynamically rendered at request time, losing performance benefits. (20% 失败率)
- **Adding console.log statements inside generateStaticParams to debug, which adds overhead and makes the timeout worse** — Logging increases I/O and slows down the generation process, potentially causing more timeouts. (50% 失败率)
