{"record":{"id":"bc24f84a5df1f474","repo":"gatsbyjs/gatsby","slug":"reporter-prefix-error-resolving-site-url","errorCode":null,"errorMessage":"${REPORTER_PREFIX} Error resolving Site URL","messagePattern":"(.+?) Error resolving Site URL","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/gatsby-plugin-sitemap/src/gatsby-node.js","lineNumber":26,"sourceCode":"exports.onPostBuild = async (\n  { graphql, reporter, basePath, pathPrefix },\n  {\n    output,\n    entryLimit,\n    query,\n    excludes,\n    resolveSiteUrl,\n    resolvePagePath,\n    resolvePages,\n    filterPages,\n    serialize,\n  }\n) => {\n  const { data: queryRecords, errors } = await graphql(query)\n\n  // resolvePages and resolveSiteUrl are allowed to be sync or async. The Promise.resolve handles each possibility\n  const siteUrl = await Promise.resolve(resolveSiteUrl(queryRecords)).catch(\n    err => reporter.panic(`${REPORTER_PREFIX} Error resolving Site URL`, err)\n  )\n\n  if (errors) {\n    reporter.panic(\n      `Error executing the GraphQL query inside gatsby-plugin-sitemap:\\n`,\n      errors\n    )\n  }\n\n  const allPages = await Promise.resolve(resolvePages(queryRecords)).catch(\n    err => reporter.panic(`${REPORTER_PREFIX} Error resolving Pages`, err)\n  )\n\n  if (!Array.isArray(allPages)) {\n    reporter.panic(\n      `${REPORTER_PREFIX} The \\`resolvePages\\` function did not return an array.`\n    )\n  }","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/gatsbyjs/gatsby/blob/8b06340921ffdf23125a365b9c9923690cb62ce6/packages/gatsby-plugin-sitemap/src/gatsby-node.js#L8-L44","documentation":"In gatsby-plugin-sitemap's onPostBuild (gatsby-node.js:25-27), the plugin calls resolveSiteUrl(queryRecords) wrapped in Promise.resolve (to handle both sync and async implementations). If resolveSiteUrl throws synchronously or its returned promise rejects, the .catch handler calls reporter.panic with the REPORTER_PREFIX and the error. resolveSiteUrl is a user-provided (or default) function that extracts the site URL from the GraphQL query result.","triggerScenarios":"A custom resolveSiteUrl function throws (e.g. accessing undefined property like data.site.siteMetadata.url when the query didn't return site metadata). The default resolveSiteUrl tries to read siteUrl from a query result that has an unexpected shape. The GraphQL query is misconfigured so queryRecords is null/undefined.","commonSituations":"Missing siteUrl in gatsby-config.js (siteMetadata). Custom resolveSiteUrl that doesn't handle edge cases. GraphQL query changed but resolveSiteUrl not updated. siteUrl not set in gatsby-config siteMetadata.","solutions":["Ensure siteMetadata.siteUrl is set in gatsby-config.js: siteMetadata: { siteUrl: 'https://example.com' }","If using a custom resolveSiteUrl, add null checks and error handling inside it","Verify the default GraphQL query returns the expected { site: { siteMetadata: { siteUrl } } } shape","Check the err object in the panic output for the specific failure"],"exampleFix":"// before (gatsby-config.js) — missing siteUrl\nsiteMetadata: {\n  title: `My Site`,\n  // siteUrl missing\n},\n\n// after\nsiteMetadata: {\n  title: `My Site`,\n  siteUrl: `https://www.example.com`,\n},","handlingStrategy":"validation","validationCode":"// Pre-build: verify siteUrl is set and resolveSiteUrl won't fail\nconst config = require('./gatsby-config')\nconst siteUrl = config.siteMetadata?.siteUrl\nif (!siteUrl) {\n  throw new Error('siteMetadata.siteUrl is required for gatsby-plugin-sitemap')\n}\ntry {\n  new URL(siteUrl)\n} catch {\n  throw new Error(`siteUrl is not a valid URL: ${siteUrl}`)\n}","typeGuard":"function isValidUrl(url: string): boolean {\n  try {\n    new URL(url)\n    return true\n  } catch {\n    return false\n  }\n}\n\n// Validate before build\nconst siteUrl = config.siteMetadata?.siteUrl\nif (!siteUrl || !isValidUrl(siteUrl)) {\n  throw new Error('siteMetadata.siteUrl must be a valid URL')\n}","tryCatchPattern":"// If using a custom resolveSiteUrl, wrap it defensively:\nresolveSiteUrl: (data) => {\n  const url = data?.site?.siteMetadata?.siteUrl\n  if (!url) {\n    throw new Error('siteUrl not found in query data — check siteMetadata config')\n  }\n  return url\n}","preventionTips":["Always set siteMetadata.siteUrl in gatsby-config.js","If using custom resolveSiteUrl, add null checks for all accessed properties","Validate the GraphQL query returns the expected data shape before building"],"tags":["sitemap","configuration","validation","site-url"],"backgroundTag":null,"analyzedSha":"8b06340921ffdf23125a365b9c9923690cb62ce6","analyzedAt":"2026-08-13T02:36:21.405Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}