{"record":{"id":"42388ed62ca58629","repo":"gatsbyjs/gatsby","slug":"nwe-were-unable-to-find-the-declaration-of-variab","errorCode":null,"errorMessage":"\\nWe were unable to find the declaration of variable \"${varName}\", which you passed as the \"query\" prop into the ${usageFunction} declaration in \"${file}\".\\n\\nPerhaps the variable name has a typo?\\n\\nAlso note that we are currently unable to use queries defined in files other than the file where the ${usageFunction} is defined. If you're attempting to import the query, please move it into \"${file}\". If being able to import queries from another file is an important capability for you, we invite your help fixing it.\\n","messagePattern":"\\\\nWe were unable to find the declaration of variable \"\\$\\{varName\\}\", which you passed as the \"query\" prop into the \\$\\{usageFunction\\} declaration in \"\\$\\{file\\}\"\\.\\\\n\\\\nPerhaps the variable name has a typo\\?\\\\n\\\\nAlso note that we are currently unable to use queries defined in files other than the file where the \\$\\{usageFunction\\} is defined\\. If you're attempting to import the query, please move it into \"\\$\\{file\\}\"\\. If being able to import queries from another file is an important capability for you, we invite your help fixing it\\.\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/gatsby/src/query/file-parser.js","lineNumber":105,"sourceCode":"  if (callee.type === `MemberExpression`) {\n    const property = callee.property\n    if (property.name === `useStaticQuery`) {\n      return referencesGatsby(\n        path,\n        path.get(`callee`).get(`object`),\n        path.node?.callee.object.name\n      )\n    }\n    return false\n  }\n  if (callee.name === `useStaticQuery`) {\n    return referencesGatsby(path, path.get(`callee`), path.node?.callee.name)\n  }\n  return false\n}\n\nconst warnForUnknownQueryVariable = (varName, file, usageFunction) =>\n  report.warn(\n    `\\nWe were unable to find the declaration of variable \"${varName}\", which you passed as the \"query\" prop into the ${usageFunction} declaration in \"${file}\".\n\nPerhaps the variable name has a typo?\n\nAlso note that we are currently unable to use queries defined in files other than the file where the ${usageFunction} is defined. If you're attempting to import the query, please move it into \"${file}\". If being able to import queries from another file is an important capability for you, we invite your help fixing it.\\n`\n  )\n\nasync function parseToAst(filePath, fileStr, { parentSpan, addError } = {}) {\n  let ast\n\n  // Since gatsby-plugin-mdx v4, we are using the resourceQuery feature of webpack's loaders to inject a content file into a page component.\n  const cleanFilePath = getPathToLayoutComponent(filePath)\n\n  // Preprocess and attempt to parse source; return an AST if we can, log an\n  // error if we can't.\n  const transpiled = await apiRunnerNode(`preprocessSource`, {\n    filename: cleanFilePath,\n    contents: fileStr,","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/gatsbyjs/gatsby/blob/e85d62f1779e353eaac1753211629a26d123e26c/packages/gatsby/src/query/file-parser.js#L87-L123","documentation":"warnForUnknownQueryVariable fires during query extraction when a page/staticQuery/useStaticQuery call receives a `query` prop referencing a variable Gatsby cannot find a declaration for in the same file. Either the variable name is misspelled/undefined or the query is imported from another file, which Gatsby's static extractor cannot follow.","triggerScenarios":"Thrown at packages/gatsby/src/query/file-parser.js:105 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Fix the typo in the variable name passed as the query prop","Declare the query string in the same file as the page/useStaticQuery call","Inline the GraphQL query literal instead of importing it"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e85d62f1779e353eaac1753211629a26d123e26c","analyzedAt":"2026-08-26T17:50:09.662Z","contentChangedAt":"2026-08-26T17:50:09.662Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}