{"record":{"id":"c8d22cb60f4192a5","repo":"facebook/docusaurus","slug":"can-t-generate-a-sitemap-with-no-items","errorCode":null,"errorMessage":"Can't generate a sitemap with no items","messagePattern":"Can't generate a sitemap with no items","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/docusaurus-plugin-sitemap/src/xml.ts","lineNumber":18,"sourceCode":"/**\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport {SitemapStream, streamToPromise} from 'sitemap';\nimport type {LastModOption, SitemapItem} from './types';\n\nexport async function sitemapItemsToXmlString(\n  items: SitemapItem[],\n  options: {lastmod: LastModOption | null},\n): Promise<string> {\n  if (items.length === 0) {\n    // Note: technically we could, but there is a bug in the lib code\n    // and the code below would never resolve, so it's better to fail fast\n    throw new Error(\"Can't generate a sitemap with no items\");\n  }\n\n  // TODO remove sitemap lib dependency?\n  //  https://github.com/ekalinin/sitemap.js\n  //  it looks like an outdated confusion super old lib\n  //  we might as well achieve the same result with a pure xml lib\n  const sitemapStream = new SitemapStream({\n    // WTF is this lib reformatting the string YYYY-MM-DD to datetime...\n    lastmodDateOnly: options?.lastmod === 'date',\n  });\n\n  items.forEach((item) => sitemapStream.write(item));\n  sitemapStream.end();\n\n  const buffer = await streamToPromise(sitemapStream);\n  return buffer.toString();\n}\n","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/facebook/docusaurus/blob/3f483e80e326cc646b54b83d564b3f0c4881b9a6/packages/docusaurus-plugin-sitemap/src/xml.ts#L1-L36","documentation":"Thrown by sitemapItemsToXmlString when called with an empty items array. Although an empty sitemap is technically valid XML, the underlying 'sitemap' library has a bug that would leave the stream unresolved, so Docusaurus fails fast instead of hanging. This is a guard inside the sitemap plugin's XML generation.","triggerScenarios":"The plugin computed zero URLs to emit (every route excluded, no docs/blog/pages routes, or all pages marked noindex/unlisted) and then attempted to render the sitemap.","commonSituations":"A site where the sitemap plugin runs but all routes are filtered out; misconfigured excludePatterns/hreflang; a dev/build environment with no content; integrating sitemap with a custom route provider that returns nothing.","solutions":["Ensure at least one crawlable route exists (a published page/doc/post that isn't noindex/unlisted).","Check that you didn't exclude the whole site via sitemap filter or head tags.","If genuinely empty sitemaps are expected, disable the sitemap plugin rather than feeding it zero items."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if (items.length === 0) {\n  // skip sitemap generation instead of calling sitemapItemsToXmlString\n  return;\n}","typeGuard":"const hasItems = (items: unknown[]): boolean => items.length > 0;","tryCatchPattern":null,"preventionTips":["Gate sitemap generation on having at least one crawlable URL.","Audit noindex/unlisted/exclude patterns that could remove all routes."],"tags":["sitemap","seo","build","library-bug"],"backgroundTag":null,"analyzedSha":"3f483e80e326cc646b54b83d564b3f0c4881b9a6","analyzedAt":"2026-08-12T13:25:04.382Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}