{"record":{"id":"4bdccabb7516ad52","repo":"gatsbyjs/gatsby","slug":"reporter-prefix-error-resolving-pages","errorCode":null,"errorMessage":"${REPORTER_PREFIX} Error resolving Pages","messagePattern":"(.+?) Error resolving Pages","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/gatsby-plugin-sitemap/src/gatsby-node.js","lineNumber":37,"sourceCode":"    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  }\n\n  reporter.verbose(\n    `${REPORTER_PREFIX} Filtering ${allPages.length} pages based on ${excludes.length} excludes`\n  )\n\n  const { filteredPages, messages } = pageFilter(\n    {\n      allPages,\n      filterPages,\n      excludes,\n    },","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/gatsbyjs/gatsby/blob/8b06340921ffdf23125a365b9c9923690cb62ce6/packages/gatsby-plugin-sitemap/src/gatsby-node.js#L19-L55","documentation":"In gatsby-plugin-sitemap's onPostBuild (gatsby-node.js:36-38), the plugin calls resolvePages(queryRecords) wrapped in Promise.resolve. If the user-provided (or default) resolvePages function throws synchronously or returns a rejected promise, the .catch handler calls reporter.panic. resolvePages is expected to return an array of page objects from the GraphQL query data.","triggerScenarios":"A custom resolvePages function throws by accessing an undefined property (e.g. data.allSitePage.nodes when the query shape differs). The default resolvePages receives null/undefined queryRecords because the query returned no data. Logic error inside a custom resolvePages implementation.","commonSituations":"Custom resolvePages that doesn't match the actual GraphQL query output shape. Query returns empty data. Plugin options changed query but not resolvePages (or vice versa).","solutions":["Check the err in the panic output for the specific thrown error","If using a custom resolvePages, ensure it handles the query result shape returned by your query option","Add null/undefined guards inside resolvePages: if (!data?.allSitePage?.nodes) return []","Test resolvePages independently by logging the queryRecords shape"],"exampleFix":"// before: custom resolvePages accessing undefined\nresolvePages: (data) => data.allSitePage.nodes.map(node => ({\n  path: node.path,\n  // if data.allSitePage is undefined, this throws\n})),\n\n// after: add guards\nresolvePages: (data) => {\n  if (!data?.allSitePage?.nodes) return []\n  return data.allSitePage.nodes.map(node => ({\n    path: node.path,\n  }))\n},","handlingStrategy":"try-catch","validationCode":"// Validate resolvePages output before passing to the plugin\nconst testData = { allSitePage: { nodes: [{ path: '/' }] } }\ntry {\n  const result = resolvePages(testData)\n  if (!Array.isArray(result)) {\n    throw new Error('resolvePages must return an array')\n  }\n} catch (e) {\n  console.error('resolvePages has a bug:', e.message)\n}","typeGuard":"function isValidPagesResult(result: unknown): result is Array<Record<string, unknown>> {\n  return Array.isArray(result) && result.every(item =>\n    typeof item === 'object' && item !== null\n  )\n}","tryCatchPattern":"// Make resolvePages defensive:\nresolvePages: (data) => {\n  try {\n    return data?.allSitePage?.nodes ?? []\n  } catch (err) {\n    console.error('resolvePages failed:', err)\n    return []\n  }\n}","preventionTips":["Make custom resolvePages functions defensive with null-checks and fallbacks","Log the queryRecords shape inside resolvePages to catch shape mismatches early","Keep resolvePages and the query option in sync — if you change one, update the other"],"tags":["sitemap","configuration","validation","resolve-pages"],"backgroundTag":null,"analyzedSha":"8b06340921ffdf23125a365b9c9923690cb62ce6","analyzedAt":"2026-08-13T02:36:21.405Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}