{"record":{"id":"1ae2b2493a0d73c6","repo":"gatsbyjs/gatsby","slug":"reporter-prefix-the-resolvepages-function-did","errorCode":null,"errorMessage":"${REPORTER_PREFIX} The `resolvePages` function did not return an array.","messagePattern":"(.+?) The `resolvePages` function did not return an array\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/gatsby-plugin-sitemap/src/gatsby-node.js","lineNumber":41,"sourceCode":"\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    },\n    { reporter }\n  )\n\n  messages.forEach(message => reporter.verbose(message))","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/gatsbyjs/gatsby/blob/8b06340921ffdf23125a365b9c9923690cb62ce6/packages/gatsby-plugin-sitemap/src/gatsby-node.js#L23-L59","documentation":"In gatsby-plugin-sitemap's onPostBuild (gatsby-node.js:40-44), after resolvePages completes, the plugin checks Array.isArray(allPages). If resolvePages returned something that is not an array (e.g. an object, undefined, null, a single page object), reporter.panic fires. The sitemap generation pipeline requires an array of page objects to iterate over.","triggerScenarios":"A custom resolvePages returns a non-array value — e.g. returns the data object directly, returns a single page instead of an array, or returns undefined/null due to a logic error. The default resolvePages is overridden but the return contract is violated.","commonSituations":"Custom resolvePages that returns data.allSitePage (the wrapper object) instead of data.allSitePage.nodes (the array). resolvePages that returns the first page only. Missing return statement inside resolvePages.","solutions":["Ensure resolvePages returns an array: wrap the result in Array.isArray() check","Return data.allSitePage.nodes (the array), not data.allSitePage (the wrapper)","Add a default empty array fallback: return result || []"],"exampleFix":"// before: returns wrapper object, not array\nresolvePages: (data) => data.allSitePage,\n\n// after: returns the nodes array\nresolvePages: (data) => data.allSitePage.nodes,","handlingStrategy":"type-guard","validationCode":"// Validate resolvePages returns an array\nconst result = resolvePages(queryRecords)\nif (!Array.isArray(result)) {\n  throw new Error(`resolvePages must return an array, got ${typeof result}`)\n}","typeGuard":"function isPageArray(value: unknown): value is Array<{ path: string }> {\n  return Array.isArray(value) &&\n    value.every(item =>\n      typeof item === 'object' &&\n      item !== null &&\n      typeof (item as { path?: unknown }).path === 'string'\n    )\n}\n\n// Usage in resolvePages:\nresolvePages: (data) => {\n  const nodes = data?.allSitePage?.nodes || []\n  return isPageArray(nodes) ? nodes : []\n}","tryCatchPattern":null,"preventionTips":["Always return the .nodes array from resolvePages, not the wrapper object","Add a defensive Array.isArray check before returning from resolvePages","Test resolvePages with real query data to verify the return shape"],"tags":["sitemap","validation","type-error","resolve-pages"],"backgroundTag":null,"analyzedSha":"8b06340921ffdf23125a365b9c9923690cb62ce6","analyzedAt":"2026-08-13T02:36:21.405Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}