nextjs - 💡(How to fix) Fix sitemap.xml with route handler and force-static breaks build — regression 16.1.7 → 16.2.0

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Error Message

Error: Invariant: failed to find source route /[store]/[lang]/c/sitemap.xml for prerender /[store]/[lang]/c/sitemap.xml

Code Example

Error: Invariant: failed to find source route /[store]/[lang]/c/sitemap.xml for prerender /[store]/[lang]/c/sitemap.xml

---

[ '%5Bstore%5D', '%5Blang%5D', '%5Bslug%5D' ]

---

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.4.0: Thu Mar 19 19:33:09 PDT 2026; root:xnu-12377.101.15~1/RELEASE_ARM64_T8112
  Available memory (MB): 16384
  Available CPU cores: 8
Binaries:
  Node: 22.22.3
  npm: 10.9.8
  Yarn: N/A
  pnpm: 11.1.3
Relevant Packages:
  next: 16.2.6 // Latest available version is detected (16.2.6).
  eslint-config-next: N/A
  react: 19.2.6
  react-dom: 19.2.6
  typescript: 5.9.3
Next.js Config:
  output: N/A
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/jordihm9/nextjs-repro-94024

To Reproduce

  1. Fork the project
  2. Create a project on Vercel
  3. Link the project with the project
  4. Create a deployment
  5. Check deployment failure and error

Current vs. Expected behavior

Expected: [store]/[lang]/c/sitemap.xml is recognized as a standalone route handler and registered in the app output map — as it was in 16.1.7. Actual — with dynamic = "force-static": build fails with:

Error: Invariant: failed to find source route /[store]/[lang]/c/sitemap.xml for prerender /[store]/[lang]/c/sitemap.xml

Actual — with dynamic = "auto": build succeeds but [store]/[lang]/c/sitemap.xml is not registered in the app output map. At runtime the request is matched against [store]/[lang]/c/[slug] instead, and params arrive URL-encoded:

[ '%5Bstore%5D', '%5Blang%5D', '%5Bslug%5D' ]

instead of the expected { store: 'en', lang: 'en' }.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.4.0: Thu Mar 19 19:33:09 PDT 2026; root:xnu-12377.101.15~1/RELEASE_ARM64_T8112
  Available memory (MB): 16384
  Available CPU cores: 8
Binaries:
  Node: 22.22.3
  npm: 10.9.8
  Yarn: N/A
  pnpm: 11.1.3
Relevant Packages:
  next: 16.2.6 // Latest available version is detected (16.2.6).
  eslint-config-next: N/A
  react: 19.2.6
  react-dom: 19.2.6
  typescript: 5.9.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Route Groups, Route Handlers

Which stage(s) are affected? (Select all that apply)

Vercel (Deployed)

Additional context

  • sitemap.xml may be treated as a keyword. Renaming the folder from sitemap.xml to any arbitrary name (e.g. asd.xml) fixes both the build failure and the param encoding issue. This may indicate sitemap.xml triggers a special path resolution case, though it could also be coincidental given that renaming also avoids the slug collision.
  • Root-level *-sitemap.xml route handlers work fine. Several route handlers at the app root without dynamic parent segments (e.g. product-sitemap.xml/route.ts, collection-sitemap.xml/route.ts) work correctly in all versions. The bug is isolated to sitemap.xml under dynamic parent segments with a sibling [slug] route.
  • A llms.txt route handler at the same [store]/[lang] level works fine. It shares the same dynamic parent segments but has no inner route group and no sibling dynamic [slug]. Both conditions appear necessary to trigger the bug: nested route groups and a sibling [slug route at the same level.
  • Only consistently reproducible on Vercel (3 parallel build workers). Local next build succeeds in all cases, pointing to a race condition in app output map registration during parallel prerendering.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING