gatsbyjs/gatsby · error
Unexpected result of config factory. Expected "function", go
Error message
Unexpected result of config factory. Expected "function", got "${typeof pageConfigFn}". What it means
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.
Source
Thrown at packages/gatsby/src/utils/page-mode.ts:135
export async function preparePageTemplateConfigs(
graphql: Runner
): Promise<void> {
const { program } = store.getState()
const pageRendererPath = `${program.directory}/${ROUTES_DIRECTORY}render-page.js`
const pageRenderer = require(pageRendererPath)
global[`__gatsbyGraphql`] = graphql
await Promise.all(
Array.from(store.getState().components.values()).map(async component => {
if (component.config) {
const componentInstance = await pageRenderer.getPageChunk({
componentChunkName: component.componentChunkName,
})
const pageConfigFn = await componentInstance.config()
if (typeof pageConfigFn !== `function`) {
throw new Error(
`Unexpected result of config factory. Expected "function", got "${typeof pageConfigFn}".`
)
}
pageConfigMap.set(component.componentChunkName, pageConfigFn)
}
})
)
delete global[`__gatsbyGraphql`]
}
View on GitHub (pinned to 8b06340921)
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.
Example fix
// before (page template)
export const config = { render: 'SSR' }
// after
import { config } from 'gatsby'
export const configFactory = config(() => ({ render: 'SSR' })) Defensive patterns
Strategy: type-guard
Validate before calling
// Before relying on a template config, verify its shape
const maybe = componentInstance.config
const result = typeof maybe === 'function' ? await maybe() : undefined
if (typeof result !== 'function') {
// skip or report this component instead of letting preparePageTemplateConfigs throw
} Type guard
const isPageConfigFn = (v: unknown): v is (...args: any[]) => any => typeof v === 'function'
Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Incompatible DSG/SSR executing environment. Function was bui
- Page for "${pathName}" not found
- Page template details for "${page.componentChunkName}" not f
- Loading indicator should never be imported in code that does
- Slice "${sliceName}" was passed props that are not serializa
AI-assisted analysis of gatsbyjs/gatsby@8b06340921 (2026-08-13).
Data as JSON: /api/errors/4d861e5b37ddc060.
Report an issue: GitHub.