nextjs
build_error
ai_generated
true
错误:路径 '/[slug]' 的静态生成失败,因为 'generateStaticParams' 没有为 slug '...' 返回值
Error: Static generation failed for path '/[slug]' because 'generateStaticParams' did not return a value for slug '...'
ID: nextjs/static-generation-failed-for-dynamic-path
82%修复率
88%置信度
1证据数
2024-03-20首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| [email protected] | active | — | — | — |
| [email protected] | active | — | — | — |
| [email protected] | active | — | — | — |
根因分析
generateStaticParams 函数缺失或不完整,因此 Next.js 在构建时无法为动态路由静态生成页面。
English
The generateStaticParams function is missing or incomplete, so Next.js cannot statically generate pages for dynamic routes during build time.
官方文档
https://nextjs.org/docs/app/api-reference/functions/generate-static-params解决方案
-
实现 generateStaticParams 以返回所有可能的 slug 值数组。如果数据源是动态的,请使用 fetch 或数据库查询。
-
如果 slug 数量太大,请使用增量静态再生(ISR),在 fetch 或页面配置中添加 revalidate。
-
使用动态渲染,设置 `export const dynamic = 'force-dynamic'` 以完全跳过静态生成。
无效尝试
常见但无效的做法:
-
80% 失败
The page will be generated for the dummy slug but still fail for other slugs if they are accessed.
-
90% 失败
This will cause a 404 for any slug not pre-generated, which is not the intended fix.
-
95% 失败
This changes the application structure and may break existing functionality.