gatsbyjs/gatsby · error

Error loading a result for the page query in "${pagePath}".

Error message

Error loading a result for the page query in "${pagePath}". Query was not run and no cached result was found.

What it means

readPageData reads the page-data JSON from public/ via readPageDataUtil; if that read fails it throws a generic message indicating the page query was never run and no cached result exists on disk.

Source

Thrown at packages/gatsby/src/utils/get-page-data.ts:118

      throw new Error(
        `Couldn't get query results for "${pagePath}" in ${(
          initialWaitForMs / 1000
        ).toFixed(3)}s.`
      )
    })
  }
}

async function readPageData(pagePath): Promise<IPageDataWithQueryResult> {
  const { program } = store.getState()

  try {
    return await readPageDataUtil(
      path.join(program.directory, `public`),
      pagePath
    )
  } catch (err) {
    throw new Error(
      `Error loading a result for the page query in "${pagePath}". Query was not run and no cached result was found.`
    )
  }
}

View on GitHub (pinned to 8b06340921)

Solutions

  1. Run gatsby develop / gatsby build so queries run and page-data is written.
  2. Clear .cache and public and rebuild from scratch.
  3. Confirm the page component compiles and its query extracts without error.
Defensive patterns

Strategy: fallback

Validate before calling

const fs = require('fs')
const path = require('path')
function pageDataFileExists(programDir, pagePath) {
  return fs.existsSync(path.join(programDir, 'public', 'page-data', pagePath, 'page-data.json'))
}

Try / catch

try {
  return await readPageData(pagePath)
} catch (err) {
  if (/Query was not run/.test(err.message)) {
    // rebuild page-data before retrying
    throw err
  }
  throw err
}

Prevention

When it happens

Trigger: The page-data file is missing on disk (build never ran queries for that page), the public dir is incomplete, or the file is corrupted/unreadable.

Common situations: First dev start before any query has run; interrupted build leaving public half-written; manually deleted public/page-data; query extraction failed silently.

Related errors


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