GoogleChrome/lighthouse · warning · Error

Invalid sitemap URL

Error message

Invalid sitemap URL

What it means

Within verifyDirective, when the directive is 'sitemap', Lighthouse attempts to parse the value as a URL using the URL constructor. If the constructor throws (the value is not a valid URL), this error is thrown. The error is caught internally by validateRobots and surfaced as a validation error item in audit results. A valid sitemap directive must point to a parseable URL.

Source

Thrown at core/audits/seo/robots-txt.js:80

const str_ = i18n.createIcuMessageFn(import.meta.url, UIStrings);

/**
 * @param {string} directiveName
 * @param {string} directiveValue
 * @throws will throw an exception if given directive is invalid
 */
function verifyDirective(directiveName, directiveValue) {
  if (!DIRECTIVE_SAFELIST.has(directiveName)) {
    throw new Error('Unknown directive');
  }

  if (directiveName === DIRECTIVE_SITEMAP) {
    let sitemapUrl;

    try {
      sitemapUrl = new URL(directiveValue);
    } catch (e) {
      throw new Error('Invalid sitemap URL');
    }

    if (!SITEMAP_VALID_PROTOCOLS.has(sitemapUrl.protocol)) {
      throw new Error('Invalid sitemap URL protocol');
    }
  }

  if (directiveName === DIRECTIVE_USER_AGENT && !directiveValue) {
    throw new Error('No user-agent specified');
  }

  if (directiveName === DIRECTIVE_ALLOW || directiveName === DIRECTIVE_DISALLOW) {
    if (directiveValue !== '' && directiveValue[0] !== '/' && directiveValue[0] !== '*') {
      throw new Error('Pattern should either be empty, start with "/" or "*"');
    }

    const dollarIndex = directiveValue.indexOf('$');

View on GitHub (pinned to 9515cd4e58)

Solutions

  1. Ensure the Sitemap directive uses a fully-qualified absolute URL: Sitemap: https://example.com/sitemap.xml
  2. Check for typos, missing protocol, or truncated URLs in the robots.txt file
  3. Validate the URL with an online robots.txt validator or Google Search Console
  4. Remove invisible characters or trailing whitespace from the sitemap line

Example fix

# before (robots.txt)
Sitemap: sitemap.xml

# after (robots.txt)
Sitemap: https://example.com/sitemap.xml
Defensive patterns

Strategy: validation

Validate before calling

// Validate sitemap URL in robots.txt before deployment
function validateSitemapUrl(directiveValue) {
  try {
    new URL(directiveValue);
  } catch (e) {
    throw new Error(`Sitemap value is not a valid URL: ${directiveValue}`);
  }
}

Prevention

When it happens

Trigger: The audited site's robots.txt contains a 'Sitemap:' directive whose value cannot be parsed by the URL constructor. For example: 'Sitemap: not-a-url', 'Sitemap: /sitemap.xml' (relative URL without host in some contexts), or 'Sitemap: ftp://' (incomplete). The URL constructor will throw on any value that does not conform to URL syntax.

Common situations: Typo in the sitemap URL; relative path instead of absolute URL; missing protocol; copy-paste error truncating the URL; special characters that break URL parsing; trailing spaces or invisible characters in the value.

Related errors


AI-assisted analysis of GoogleChrome/lighthouse@9515cd4e58 (2026-08-13). Data as JSON: /api/errors/bcafa152d9306b0c. Report an issue: GitHub.