nextjs - 💡(How to fix) Fix [Bug] Sitemap renders as HTML instead of XML when alternates are included [1 comments, 2 participants]

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…
GitHub stats
vercel/next.js#86242Fetched 2026-04-08 02:11:56
View on GitHub
Comments
1
Participants
2
Timeline
7
Reactions
0
Author
Timeline (top)
labeled ×3closed ×1commented ×1issue_type_added ×1

Code Example

N/A
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

N/A

To Reproduce

  1. Create a sitemap.ts file (App Router).
  2. Add alternates
  3. Request /sitemap.xml.
  4. Observe that the response is wrapped in an <html> document instead of being served as XML.

Current vs. Expected behavior

In Next.js v16.0.3, enabling the alternates option inside the sitemap.ts configuration causes the generated sitemap.xml to render as an HTML document instead of a valid XML sitemap.

Provide environment information

N/A

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

Internationalization (i18n), Metadata

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

next dev (local), next build (local), next start (local)

Additional context

No response

extent analysis

TL;DR

  • The issue with the sitemap.xml being wrapped in an HTML document instead of being served as XML when alternates are enabled in Next.js v16.0.3 may be resolved by adjusting the sitemap.ts configuration or the server settings to properly handle XML responses.

Guidance

  • Review the sitemap.ts file to ensure that the alternates option is correctly configured and that the XML response is properly set.
  • Verify that the server is configured to serve XML files with the correct MIME type (application/xml) to prevent them from being wrapped in HTML.
  • Check if there are any middleware or plugins that might be interfering with the XML response and adjust their configurations accordingly.
  • Test the sitemap.xml generation with a minimal configuration to isolate if the issue is related to a specific setting or the overall setup.

Example

No specific code example can be provided without more details on the sitemap.ts configuration and the server setup.

Notes

The exact solution depends on the specifics of the Next.js configuration, server settings, and any middleware or plugins in use. Without more detailed information about these aspects, it's challenging to provide a precise fix.

Recommendation

  • Apply workaround: Adjust the sitemap.ts configuration and server settings to ensure proper handling of XML responses, as the root cause seems related to how the server or Next.js handles XML output when alternates are enabled.

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