{"record":{"id":"2ee3ff6d174ae223","repo":"gatsbyjs/gatsby","slug":"reporter-prefix-error-serializing-pages","errorCode":null,"errorMessage":"${REPORTER_PREFIX} Error serializing pages","messagePattern":"(.+?) Error serializing pages","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/gatsby-plugin-sitemap/src/gatsby-node.js","lineNumber":77,"sourceCode":"  messages.forEach(message => reporter.verbose(message))\n\n  reporter.verbose(\n    `${REPORTER_PREFIX} ${filteredPages.length} pages remain after filtering`\n  )\n\n  const serializedPages = []\n\n  for (const page of filteredPages) {\n    try {\n      const { url, ...rest } = await Promise.resolve(\n        serialize(page, { resolvePagePath })\n      )\n      serializedPages.push({\n        url: prefixPath({ url, siteUrl, pathPrefix: basePath }),\n        ...rest,\n      })\n    } catch (err) {\n      reporter.panic(`${REPORTER_PREFIX} Error serializing pages`, err)\n    }\n  }\n\n  const sitemapWritePath = path.join(`public`, output)\n  const sitemapPublicPath = path.posix.join(pathPrefix, output)\n\n  return simpleSitemapAndIndex({\n    hostname: siteUrl,\n    publicBasePath: sitemapPublicPath,\n    destinationDir: sitemapWritePath,\n    sourceData: serializedPages,\n    limit: entryLimit,\n    gzip: false,\n  })\n}\n","sourceCodeStart":59,"sourceCodeEnd":93,"githubUrl":"https://github.com/gatsbyjs/gatsby/blob/8b06340921ffdf23125a365b9c9923690cb62ce6/packages/gatsby-plugin-sitemap/src/gatsby-node.js#L59-L93","documentation":"In gatsby-plugin-sitemap's onPostBuild (gatsby-node.js:67-78), the plugin iterates over filteredPages and calls serialize(page, { resolvePagePath }) for each. If serialize throws synchronously or its promise rejects, reporter.panic fires with the error. serialize is expected to return an object containing at least a 'url' property for each page.","triggerScenarios":"A custom serialize function throws (e.g. accessing page.path when page has a different shape). The default serialize encounters a page object without expected fields. serialize returns a promise that rejects.","commonSituations":"Custom serialize that assumes a page field exists but doesn't (e.g. page.context.slug). Pages created by other plugins with non-standard shapes. Custom serialize with a bug that only manifests on certain pages.","solutions":["Check the err in the panic output for the specific serialize error and which page triggered it","Add null checks inside serialize: const path = page.path || ''","Log the page object inside serialize to verify its shape","Test serialize with the actual page objects from your GraphQL query"],"exampleFix":"// before: serialize accessing potentially missing field\nserialize: (page) => ({\n  url: page.path,\n  changefreq: page.context.sitemap changefreq, // may be undefined\n}),\n\n// after: add defaults\nserialize: (page) => ({\n  url: page.path,\n  changefreq: page.context?.sitemapChangefreq || `weekly`,\n  priority: page.context?.sitemapPriority || 0.7,\n}),","handlingStrategy":"try-catch","validationCode":"// Test serialize with a sample page object before building\nconst samplePage = { path: '/test/', context: {} }\ntry {\n  const result = serialize(samplePage, { resolvePagePath: (p) => p.path })\n  if (!result || typeof result.url !== 'string') {\n    throw new Error('serialize must return an object with a url property')\n  }\n} catch (e) {\n  console.error('serialize function has a bug:', e.message)\n}","typeGuard":"interface SerializedPage {\n  url: string\n  changefreq?: string\n  priority?: number\n}\n\nfunction isSerializedPage(value: unknown): value is SerializedPage {\n  return typeof value === 'object' &&\n    value !== null &&\n    typeof (value as { url?: unknown }).url === 'string'\n}","tryCatchPattern":"// Make serialize defensive:\nserialize: (page, { resolvePagePath }) => {\n  const path = resolvePagePath ? resolvePagePath(page) : page.path\n  if (!path) {\n    throw new Error(`Page missing path: ${JSON.stringify(page)}`)\n  }\n  return {\n    url: path,\n    changefreq: page.context?.changefreq || 'weekly',\n    priority: page.context?.priority || 0.7,\n  }\n}","preventionTips":["Add null checks for all page properties accessed inside serialize","Use optional chaining (page.context?.field) with fallback defaults","Test serialize with various page shapes from your actual build"],"tags":["sitemap","configuration","validation","serialize"],"backgroundTag":null,"analyzedSha":"8b06340921ffdf23125a365b9c9923690cb62ce6","analyzedAt":"2026-08-13T02:36:21.405Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}