gatsbyjs/gatsby · error

10126

10126

Error message

${context.path}/${context.configName} cannot export a function.

A ${context.configName} exported as a function can only be used as a theme and not run directly.
If you are trying to run a theme directly, use the theme in an example site or starter instead and run that site to test.
If you are in the root gatsby-config for your site, change the export to be an object and not a function as functions
are not supported in the root gatsby-config.

What it means

Error "${context.path}/${context.configName} cannot export a function. A ${context.configName} exported as a function can only be used as a theme and not run directly. If you are trying to run a theme directly, use the theme in an example site or starter instead and run that site to test. If you are in the root gatsby-config for your site, change the export to be an object and not a function as functions are not supported in the root gatsby-config." thrown in gatsbyjs/gatsby.

Source

Thrown at packages/gatsby/src/bootstrap/load-config/index.ts:29

export async function loadConfig({
  siteDirectory,
  processFlags = false,
}: {
  siteDirectory: string
  processFlags?: boolean
  program?: IProgram
}): Promise<IGatsbyConfig> {
  // Try opening the site's gatsby-config.js file.
  const { configModule, configFilePath } = await getConfigFile(
    siteDirectory,
    `gatsby-config`
  )
  let config = preferDefault(configModule)

  // The root config cannot be exported as a function, only theme configs
  if (typeof config === `function`) {
    reporter.panic({
      id: `10126`,
      context: {
        configName: `gatsby-config`,
        siteDirectory,
      },
    })
  }

  if (processFlags) {
    // Setup flags
    const {
      enabledConfigFlags,
      unknownFlagMessage,
      unfitFlagMessage,
      message,
    } = handleFlags(availableFlags, config?.flags ?? {})

    if (unknownFlagMessage !== ``) {

View on GitHub (pinned to e85d62f177)

Solutions

  1. In the root gatsby-config, export a plain object instead of a function
  2. If developing a theme, run it through an example site or starter instead of directly
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at packages/gatsby/src/bootstrap/load-config/index.ts:29 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of gatsbyjs/gatsby@e85d62f177 (2026-08-26). Data as JSON: /api/errors/c90232e83290b1ab. Report an issue: GitHub.