nextjs build_error ai_generated true

Error: Page '/[slug]' is missing generateStaticParams() which is required with 'output: export'

ID: nextjs/static-params-missing

Also available as: JSON · Markdown
92%Fix Rate
91%Confidence
80Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
14 active

Root Cause

When using Next.js static export (output: 'export' in next.config.js), all dynamic routes must define a generateStaticParams() function so that Next.js knows which paths to pre-render at build time. Without a server to handle dynamic routes at runtime, every possible route parameter combination must be enumerated statically. This error occurs when a dynamic route segment (e.g., [slug], [id], [...params]) exists but does not export generateStaticParams(). Fix by adding the function to all dynamic route pages, or by restructuring the route to not use dynamic segments if the parameter set is unknowable at build time.

generic

Workarounds

  1. 94% success Add generateStaticParams() to the dynamic route page that returns all valid parameter combinations
    Export an async generateStaticParams function from the page: // app/blog/[slug]/page.tsx
    export async function generateStaticParams() {
      const posts = await fetch('https://api.example.com/posts').then(r => r.json());
      return posts.map((post: { slug: string }) => ({
        slug: post.slug,
      }));
    }
    
    export default function BlogPost({ params }: { params: { slug: string } }) {
      // render post
    }
    
    For nested dynamic routes like /blog/[category]/[slug], return objects with both params: return [{ category: 'tech', slug: 'my-post' }, ...];
  2. 90% success Switch from output: 'export' to standard Next.js deployment if dynamic routes cannot be fully enumerated
    If your dynamic routes depend on user-generated content or data that cannot be enumerated at build time, remove output: 'export' from next.config.js and deploy to a platform that supports Next.js server-side rendering (Vercel, AWS, Docker with standalone output): // next.config.js
    module.exports = {
      // Remove: output: 'export',
      // Optionally use standalone for Docker:
      output: 'standalone',
    };
    
    With server-side rendering, dynamic routes are rendered on-demand and do not require generateStaticParams() (though it can still be used for ISR/SSG optimization)
  3. 88% success Use generateStaticParams with a fallback data source for known parameter subsets
    For sites with many dynamic pages, generate the most important subset statically: // app/products/[id]/page.tsx
    export async function generateStaticParams() {
      // Generate top 100 products statically
      const topProducts = await db.products.findMany({
        where: { featured: true },
        take: 100,
        select: { id: true },
      });
      return topProducts.map(p => ({ id: String(p.id) }));
    }
    
    // For non-exported builds, set dynamicParams to handle the rest at runtime:
    export const dynamicParams = true; // Only works without output: 'export'
    
    For pure static export, you must include all possible params. Consider generating a manifest file during CI that lists all valid params

Dead Ends

Common approaches that don't work:

  1. Removing the dynamic route segment and using query parameters instead (e.g., /page?slug=value) 85% fail

    While this avoids the dynamic route requirement, static exports cannot access query parameters at build time. Pages using useSearchParams() in static export mode will render with empty parameters during the build, producing incorrect or empty pre-rendered pages. This fundamentally breaks the static generation model and produces non-functional pages

  2. Adding 'dynamicParams = true' or 'dynamic = force-dynamic' to the page to skip static generation 95% fail

    Static export mode (output: 'export') does not support dynamic rendering at runtime. There is no server to handle requests for paths not generated at build time. Setting dynamicParams = true or dynamic = 'force-dynamic' is incompatible with output: 'export' and will produce a build error stating that dynamic server usage cannot be statically exported

  3. Returning an empty array from generateStaticParams to skip all dynamic pages 90% fail

    Returning an empty array means no pages are generated for that dynamic route. All URLs matching the pattern (e.g., /blog/any-slug) will result in 404 errors in the exported site. This technically satisfies the build requirement but produces a broken site with no actual dynamic content pages

Error Chain

Leads to:
Preceded by: