{"record":{"id":"4d861e5b37ddc060","repo":"gatsbyjs/gatsby","slug":"unexpected-result-of-config-factory-expected-fun","errorCode":null,"errorMessage":"Unexpected result of config factory. Expected \"function\", got \"${typeof pageConfigFn}\".","messagePattern":"Unexpected result of config factory\\. Expected \"function\", got \"(.+?)\"\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/gatsby/src/utils/page-mode.ts","lineNumber":135,"sourceCode":"\nexport async function preparePageTemplateConfigs(\n  graphql: Runner\n): Promise<void> {\n  const { program } = store.getState()\n  const pageRendererPath = `${program.directory}/${ROUTES_DIRECTORY}render-page.js`\n\n  const pageRenderer = require(pageRendererPath)\n  global[`__gatsbyGraphql`] = graphql\n\n  await Promise.all(\n    Array.from(store.getState().components.values()).map(async component => {\n      if (component.config) {\n        const componentInstance = await pageRenderer.getPageChunk({\n          componentChunkName: component.componentChunkName,\n        })\n        const pageConfigFn = await componentInstance.config()\n        if (typeof pageConfigFn !== `function`) {\n          throw new Error(\n            `Unexpected result of config factory. Expected \"function\", got \"${typeof pageConfigFn}\".`\n          )\n        }\n\n        pageConfigMap.set(component.componentChunkName, pageConfigFn)\n      }\n    })\n  )\n  delete global[`__gatsbyGraphql`]\n}\n","sourceCodeStart":117,"sourceCodeEnd":146,"githubUrl":"https://github.com/gatsbyjs/gatsby/blob/8b06340921ffdf23125a365b9c9923690cb62ce6/packages/gatsby/src/utils/page-mode.ts#L117-L146","documentation":"Thrown by preparePageTemplateConfigs while preloading each page template's SSR/DSG config. After require-ing a component chunk and calling its exported `config()` method, Gatsby expects the return value to be a function (the actual page-config handler). If the template's config export resolves to anything other than a function, Gatsby cannot use it to drive SSR/DSG rendering and aborts. This guards the page-config contract introduced for server-side rendering modes.","triggerScenarios":"A registered component in the store has `component.config` truthy, so Gatsby calls `pageRenderer.getPageChunk(...)` then `componentInstance.config()`, but that call resolves to undefined/object/string instead of a function. Common when a page template exports `config` from `gatsby` but re-exports it incorrectly, or when a third-party plugin injects a component with a malformed `config` field.","commonSituations":"Upgrading a site to a Gatsby version that introduced the page-config API while the page template exports a non-standard `config` value; using DSG/SSR with a template whose `config` export is shadowed by a default export; plugin-authored components registering a `config` field that is not the Gatsby config factory.","solutions":["Open the page template file mapped to the failing componentChunkName and verify its `config` export is `export const config = () => { ... }` (a function returning a function) or uses `import { config } from 'gatsby'`.","Check that no plugin or wrapper component is attaching a `config` property that is not the Gatsby config factory.","Clear `.cache` and `node_modules` and reinstall to discard stale chunks: `rm -rf .cache node_modules && npm install`.","If the error names a `typeof` of `undefined`, confirm the template actually calls the Gatsby-provided `config` helper rather than re-assigning it."],"exampleFix":"// before (page template)\nexport const config = { render: 'SSR' }\n\n// after\nimport { config } from 'gatsby'\nexport const configFactory = config(() => ({ render: 'SSR' }))","handlingStrategy":"type-guard","validationCode":"// Before relying on a template config, verify its shape\nconst maybe = componentInstance.config\nconst result = typeof maybe === 'function' ? await maybe() : undefined\nif (typeof result !== 'function') {\n  // skip or report this component instead of letting preparePageTemplateConfigs throw\n}","typeGuard":"const isPageConfigFn = (v: unknown): v is (...args: any[]) => any =>\n  typeof v === 'function'","tryCatchPattern":null,"preventionTips":["Always export the page config via Gatsby's `config` helper from the template.","Never attach a custom `config` property to components injected by plugins.","Run a clean build after upgrading Gatsby across a page-config API boundary."],"tags":["ssr","dsg","page-config","template","webpack-chunk"],"backgroundTag":null,"analyzedSha":"8b06340921ffdf23125a365b9c9923690cb62ce6","analyzedAt":"2026-08-13T02:36:21.405Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}