nextjs resource_error ai_generated partial

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

Also available as: JSON · Markdown · 中文
80%Fix Rate
86%Confidence
1Evidence
2023-08-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
13.4.0 active
13.5.0 active
14.0.0 active
14.1.0 active
14.2.0 active
15.0.0 active

Root Cause

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.

generic

中文

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

Official Documentation

https://nextjs.org/docs/messages/static-generation-timeout

Workarounds

  1. 85% success Increase the static generation timeout in next.config.js: module.exports = { staticPageGenerationTimeout: 120 }; (value in seconds). This gives more time for complex builds.
    Increase the static generation timeout in next.config.js: module.exports = { staticPageGenerationTimeout: 120 }; (value in seconds). This gives more time for complex builds.
  2. 80% success 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 })); }
    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. 75% success Use dynamicParams: false in the page component to ensure only explicitly returned paths are pre-rendered, and fall back to dynamic rendering for others.
    Use dynamicParams: false in the page component to ensure only explicitly returned paths are pre-rendered, and fall back to dynamic rendering for others.

中文步骤

  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.

Dead Ends

Common approaches that don't work:

  1. Setting generateStaticParams to return an empty array to avoid the timeout 20% fail

    This defeats the purpose of static generation; all pages will be dynamically rendered at request time, losing performance benefits.

  2. Adding console.log statements inside generateStaticParams to debug, which adds overhead and makes the timeout worse 50% fail

    Logging increases I/O and slows down the generation process, potentially causing more timeouts.