gatsbyjs/gatsby · error

Couldn't find temp query result for "${pagePath}".

Error message

Couldn't find temp query result for "${pagePath}".

What it means

readPageQueryResult reads the page's query result from the LMDB page-query-results cache; if the stored value is not a string (key missing/evicted/corrupted) it throws. It indicates the temp query result for that page path was never persisted.

Source

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

  return savePageQueryResultsPromise
}

export async function savePageQueryResult(
  pagePath: string,
  stringifiedResult: string
): Promise<void> {
  savePageQueryResultsPromise = getLMDBPageQueryResultsCache().set(
    pagePath,
    stringifiedResult
  ) as Promise<void>
}

export async function readPageQueryResult(pagePath: string): Promise<string> {
  const stringifiedResult = await getLMDBPageQueryResultsCache().get(pagePath)
  if (typeof stringifiedResult === `string`) {
    return stringifiedResult
  }
  throw new Error(`Couldn't find temp query result for "${pagePath}".`)
}

export async function writePageData(
  publicDir: string,
  pageData: IPageDataInput,
  slicesUsedByTemplates: Map<string, ICollectedSlices>,
  slices: IGatsbyState["slices"]
): Promise<string> {
  const result = await readPageQueryResult(pageData.path)

  const outputFilePath = generatePageDataPath(publicDir, pageData.path)

  const body = constructPageDataString(
    pageData,
    result,
    slicesUsedByTemplates,
    slices
  )

View on GitHub (pinned to 8b06340921)

Solutions

  1. Ensure writePageQueryResult succeeds for the page path before readPageQueryResult is called.
  2. Clear the .cache-dir (LMDB) and public and rerun the build.
  3. Confirm the page query actually ran (check query-runner logs) before invoking read.
Defensive patterns

Strategy: retry

Validate before calling

async function pageResultWritten(pagePath) {
  const cache = getLMDBPageQueryResultsCache()
  return typeof (await cache.get(pagePath)) === 'string'
}

Type guard

async function resultIsCached(cache, pagePath) { return typeof (await cache.get(pagePath)) === 'string' }

Try / catch

try {
  return await readPageQueryResult(pagePath)
} catch (err) {
  if (/Couldn't find temp query result/.test(err.message)) {
    // re-run the page query, then retry once
    await writePageQueryResult(pagePath, result)
    return readPageQueryResult(pagePath)
  }
  throw err
}

Prevention

When it happens

Trigger: writePageData/readPageQueryResult is called before writePageQueryResult has stored the result; LMDB cache miss or eviction; cache corruption.

Common situations: Race during build where read precedes write; corrupted .cache-dir; querying a page whose query never ran; LMDB lock or disk issue.

Related errors


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