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.

Error:exportconstdynamic="force-static"/exportconstrevalidatenotconfiguredonroute"/sitemap.xml"with"output:export".

Solution

This issue can be resolved by adding the following two exports to sitemap.ts:

ieee}mxxxppppsooorrrrrctttts/ia{ccdtpooeepMnnfm/essaastttupialtddrtgeayeemtnvfnaaaauepRmlnr.oiicatucdttstaiie=tooenn}'f=slfoiorrftgocaeimelmc-sa'sepnt;(ea)xt:ti'cM;'e;tadataRoute.Sitemap{

Implementation Example

iieee}mmxxxpppppcc]c)rooooooo;o;errrrrnnns}ttttttss'/st)utt,aetaulcp)r{{ccdbxtrahrnooebsasilsaiMrnnfatumic:tnoseossasatptPMgrituttuetH'lea`oeitatlUio,emg$dFtedidrtrcm'ae{irymanyelPe,psbfe:atgnvfaE.aiqpaaau=gpnmseupER}mlneataedeanoiicpsgrpU:ngtufcdtrei(rcertraio=e(lnyieo=tocsp}e:=emene[:a/w=s}'sg$p=;'f=ssMe{Daf@oi.e)lagrrftetoteicaena=cem1elmvd>a(=?8-sa.al)='nsepNt(e,=1n/t;(Ea{}era)XR$:xot:To{tui_up0'tcMPta?.;i'eUeg8n;tB.e',gaLS}d'dIi`a;aCt,it_elaSmyRIa'oTpuE:t_=eU'.RrwSLoeiuettkeilmnya'g'ph.tla{tospc:ac/lo/enlsso.tcf,allahtoMsatp:(3(0l0o0c'a;le)=>

Verification

With this implementation, /out/sitemap.xml is generated correctly when running npm run build.

Notes

  • dynamic = 'force-static' alone is not sufficient; revalidate = false is 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:

  1. Generate sitemap.xml with a build script
  2. 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.

References