gatsbyjs/gatsby · error
Could not find query ${pagePath}
Error message
Could not find query ${pagePath} What it means
The page exists in the redux pages map but queries.trackedQueries has no entry for its path, meaning the query runner has not registered a tracked query for it. getPageData cannot return data without a tracked query, so it throws.
Source
Thrown at packages/gatsby/src/utils/get-page-data.ts:35
}
async function doGetPageData(
pagePath: string,
waitForMS: number,
initialWaitForMs: number
): Promise<IPageDataWithQueryResult> {
const { queries, pendingPageDataWrites, pages } = store.getState()
if (!pages.has(pagePath)) {
throw new Error(
`Page "${pagePath}" doesn't exist. It might have been deleted recently.`
)
}
const query = queries.trackedQueries.get(pagePath)
if (!query) {
throw new Error(`Could not find query ${pagePath}`)
}
if (query.running !== 0) {
return waitNextPageData(pagePath, waitForMS, initialWaitForMs)
}
if (query.dirty !== 0) {
emitter.emit(`QUERY_RUN_REQUESTED`, { pagePath })
return waitNextPageData(pagePath, waitForMS, initialWaitForMs)
}
if (pendingPageDataWrites.pagePaths.has(pagePath)) {
return waitNextPageData(pagePath, waitForMS, initialWaitForMs)
}
// Results are up-to-date
return readPageData(pagePath)
}
async function waitNextPageData(
pagePath: string,
remainingTime: number,View on GitHub (pinned to 8b06340921)
Solutions
- Ensure the page component goes through the standard query extraction pipeline (real component file with a query).
- Restart the dev server / rerun the build so tracking is repopulated.
- Verify the page component actually exports a pageQuery or is at least a valid component.
Defensive patterns
Strategy: retry
Validate before calling
const { store } = require('gatsby/dist/redux')
function hasTrackedQuery(pagePath) {
return store.getState().queries.trackedQueries.has(pagePath)
} Type guard
function pageHasTrackedQuery(state, pagePath) { return state.queries.trackedQueries.has(pagePath) } Try / catch
try {
const data = await getPageData(pagePath)
} catch (err) {
if (/Could not find query/.test(err.message)) {
// wait for query tracking to catch up, then retry once
await once(emitter, 'CLEAR_PENDING_PAGE_DATA_WRITE')
return getPageData(pagePath)
}
throw err
} Prevention
- Give the dev server time to extract queries before requesting brand-new pages.
- Ensure page components are real files with a (possibly empty) page query.
- Avoid creating pages after the query-tracking phase has begun.
When it happens
Trigger: A page was created but query extraction/tracking has not run for it (component with no exported query, very-late page creation, internal state desync).
Common situations: Pages created after query tracking started; component files without a graphql export; custom page creation bypassing the standard pipeline; corrupted redux state.
Related errors
- Page "${pagePath}" doesn't exist. It might have been deleted
- Couldn't get query results for "${pagePath}" in ${(initialWa
- Pages can only be created by plugins. There wasn't a plugin
- Error loading a result for the page query in "${pagePath}".
- Couldn't find temp query result for "${pagePath}".
AI-assisted analysis of gatsbyjs/gatsby@8b06340921 (2026-08-13).
Data as JSON: /api/errors/85960399d8ca3b50.
Report an issue: GitHub.