This article was written by AI after a human verified the implementation.
Background
When using static site generation (output: 'export') in Next.js 15, errors may occur with the sitemap.ts implementation.
Solution
This issue can be resolved by adding the following two exports to sitemap.ts:
Implementation Example
Verification
With this implementation, /out/sitemap.xml is generated correctly when running npm run build.
Notes
dynamic = 'force-static'alone is not sufficient;revalidate = falseis also required- Environment variables and imported modules can be used
- Dynamic values can also be used as long as they are statically resolved at build time
Alternative Approaches
If the above method does not work, the following alternatives are available:
- Generate sitemap.xml with a build script
- Place a static sitemap.xml in the public directory
Summary
Even when using output: 'export' in Next.js 15, sitemap generation using sitemap.ts is possible with the appropriate configuration. This method enables type-safe sitemap generation while leveraging Next.js standard features.