Skip to content

Rule · SEO

Sitemap isn't valid sitemap XML or exceeds protocol limits

seo/sitemap-invaliderrorvoid seoupdated

Why it matters

Malformed XML, HTML served at /sitemap.xml, or files over 50,000 URLs / 50 MB are rejected.

How to fix it

Generate sitemaps with app/sitemap.ts; split large sites with generateSitemaps and add a sitemap index route.

Example

ts
// app/sitemap-index.xml/route.ts — Next doesn't emit an index for generateSitemaps
export const dynamic = 'force-static'
export async function GET() {
  const ids = await generateSitemaps()
  const locs = ['https://acme.example/sitemap.xml', ...ids.map(({ id }) => 'https://acme.example/products/sitemap/' + id + '.xml')]
  const xml = '<?xml version="1.0" encoding="UTF-8"?>\n<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n' +
    locs.map((loc) => '  <sitemap><loc>' + loc + '</loc></sitemap>').join('\n') + '\n</sitemapindex>\n'
  return new Response(xml, { headers: { 'Content-Type': 'application/xml; charset=utf-8' } })
}

References

void seo reports 60 rules in this category. What search engines need from the raw response: status codes, titles and descriptions in <head>, self-referencing canonicals, one h1, crawlable links, Open Graph, icons, robots.txt and a sitemap with real dates.