gatsbyjs/gatsby · error

The GraphQL query in the non-page component "${component}" w

Error message

The GraphQL query in the non-page component "${component}" will not be run.

What it means

In updateStateAndRunQueries (query watcher, first bootstrap run), a component that is not a page (not registered via createPage) exports a GraphQL page query. Gatsby only runs queries for page components (and static queries), so the query is skipped and this warning tells you it will never execute.

Source

Thrown at packages/gatsby/src/query/query-watcher.ts:274

    )
  })

  let queriesWillNotRun = false
  queries.forEach((query, component) => {
    const queryWillRun = handleQuery(snapshot, query, component)

    if (queryWillRun) {
      watchComponent(component)
      // Check if this is a page component.
      // If it is and this is our first run during bootstrap,
      // show a warning about having a query in a non-page component.
    } else if (
      isFirstRun &&
      !snapshot.componentsWithCleanFilePaths.has(
        getPathToLayoutComponent(component)
      )
    ) {
      report.warn(
        `The GraphQL query in the non-page component "${component}" will not be run.`
      )
      queriesWillNotRun = true
    }
  })

  if (queriesWillNotRun) {
    report.log(report.stripIndent`

        Exported queries are only executed for page components. It's possible you're trying to create pages in your gatsby-node.js and that's failing for some reason.

        If the failing component is a regular component and not intended to be a page component, you generally want to use "useStaticQuery" (https://www.gatsbyjs.com/docs/how-to/querying-data/use-static-query/) instead of exporting a page query.

        If you're more experienced with GraphQL, you can also export GraphQL fragments from components and compose the fragments in the Page component query and pass data down into the child component (https://www.gatsbyjs.com/docs/reference/graphql-data-layer/using-graphql-fragments/)

      `)
  }

View on GitHub (pinned to e85d62f177)

Solutions

  1. Register the component as a page via createPage in gatsby-node, or move the query into the actual page template
  2. Convert the page query to useStaticQuery if the component is shared/non-page
  3. Remove the exported query if it is unused
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at packages/gatsby/src/query/query-watcher.ts:274 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/32f3e946c3b961f4. Report an issue: GitHub.