gatsbyjs/gatsby · error

The result of this StaticQuery could not be fetched. This i

Error message

The result of this StaticQuery could not be fetched.

This is likely a bug in Gatsby and if refreshing the page does not fix it, please open an issue in https://github.com/gatsbyjs/gatsby/issues

What it means

`useStaticQuery` looked up its query hash in `StaticQueryContext` and found no entry with `.data`. The hash should have been injected at build time by the query extractor; a miss means the runtime context and the build-time extracted data diverged. The message itself labels this a likely Gatsby bug.

Source

Thrown at packages/gatsby/cache-dir/static-query.js:83

  const context = React.useContext(StaticQueryContext)

  // query is a stringified number like `3303882` when wrapped with graphql, If a user forgets
  // to wrap the query in a grqphql, then casting it to a Number results in `NaN` allowing us to
  // catch the misuse of the API and give proper direction
  if (isNaN(Number(query))) {
    throw new Error(`useStaticQuery was called with a string but expects to be called using \`graphql\`. Try this:

import { useStaticQuery, graphql } from 'gatsby';

useStaticQuery(graphql\`${query}\`);
`)
  }

  if (context[query]?.data) {
    return context[query].data
  } else {
    throw new Error(
      `The result of this StaticQuery could not be fetched.\n\n` +
        `This is likely a bug in Gatsby and if refreshing the page does not fix it, ` +
        `please open an issue in https://github.com/gatsbyjs/gatsby/issues`
    )
  }
}

export { StaticQuery, StaticQueryContext, useStaticQuery }

View on GitHub (pinned to 8b06340921)

Solutions

  1. Stop the dev/build process and delete `.cache` and `public`, then re-run.
  2. Verify all Gatsby packages share one version (`npm ls @gatsbyjs/reach-router` / `gatsby` etc.).
  3. Trigger a hard refresh in the browser to rule out a stale client bundle.
  4. If it persists, capture the query and open an issue at the URL in the message.
Defensive patterns

Strategy: retry

Try / catch

// In app code you generally cannot catch this usefully (it throws during render).
// Treat it as a build/CI signal: detect non-zero exit from `gatsby build` and
// clear `.cache`/`public` before retrying.
try {
  await runBuild()
} catch (e) {
  if (/StaticQuery could not be fetched/.test(String(e))) {
  await fs.rm(".cache", { recursive: true, force: true })
  await fs.rm("public", { recursive: true, force: true })
  throw e
  }
  throw e
}

Prevention

When it happens

Trigger: Running after a build/extract that failed to register the static query; the component's compiled hash differs from what is in `page-data`/`app-data`; SSR or dev-server stale state serving mismatched data.

Common situations: Leftover `.cache`/`public` after a Gatsby upgrade; switching branches with different queries without clearing cache; a failed partial build; HMR desync in develop.

Related errors


AI-assisted analysis of gatsbyjs/gatsby@8b06340921 (2026-08-13). Data as JSON: /api/errors/c1121c4cf51b42be. Report an issue: GitHub.