{"record":{"id":"148c15fa54dc5717","repo":"TanStack/query","slug":"in-file-filepath-at-line-node-loc-start-line-148c15","errorCode":null,"errorMessage":"In file ${filePath} at line ${node.loc.start.line} the \\`${keyName}\\` couldn't be found. Did you forget to add it?","messagePattern":"In file (.+?) at line (.+?) the \\\\`(.+?)\\\\` couldn't be found\\. Did you forget to add it\\?","errorType":"exception","errorClass":"UnprocessableKeyError","httpStatus":null,"severity":"warning","filePath":"packages/query-codemods/src/v4/utils/replacers/key-replacer.cjs","lineNumber":121,"sourceCode":"    if (methodArguments.length === 0) {\n      return node\n    }\n\n    try {\n      const [firstArgument, ...restOfTheArguments] = methodArguments\n\n      if (\n        jscodeshift.match(firstArgument, {\n          type: jscodeshift.ObjectExpression.name,\n        })\n      ) {\n        const originalKey = getPropertyFromObjectExpression(\n          firstArgument,\n          keyName,\n        )\n\n        if (!originalKey) {\n          throw new UnprocessableKeyError(\n            `In file ${filePath} at line ${node.loc.start.line} the \\`${keyName}\\` couldn't be found. Did you forget to add it?`,\n          )\n        }\n\n        const restOfTheProperties = firstArgument.properties.filter(\n          (item) => item.key.name !== keyName,\n        )\n\n        return buildWithTypeArguments(node, (originalNode) =>\n          jscodeshift.callExpression(originalNode.original.callee, [\n            jscodeshift.objectExpression([\n              createKeyProperty(originalKey.value),\n              ...restOfTheProperties,\n            ]),\n            ...restOfTheArguments,\n          ]),\n        )\n      }","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/TanStack/query/blob/159982c80b844487054155c38ffc760fe4208daf/packages/query-codemods/src/v4/utils/replacers/key-replacer.cjs#L103-L139","documentation":"`UnprocessableKeyError` from `key-replacer.cjs` when the first argument to a query hook is an `ObjectExpression` (already an options object) but the expected key property (e.g. `queryKey`) is absent. The codemod cannot synthesize a key the developer never wrote, so it asks the user to add it manually.","triggerScenarios":"A call like `useQuery({ queryFn: fetch, ... })` where `queryKey` was omitted; an options object whose key uses a different property name (typo, or `variables` from graphql-query); spread objects where the key is in a different fragment not visible to the codemod.","commonSituations":"Older code that did not require a `queryKey`; refactors that renamed the property; codemod run on partial migration; GraphQL-query wrappers using different property names.","solutions":["Add the missing `queryKey` to the options object manually and re-run the codemod.","Verify the property name matches what the codemod expects (`queryKey`, `mutationKey`, etc.).","If the key is genuinely dynamic, declare it as an array literal at the call site.","Skip the codemod for that file and migrate it by hand."],"exampleFix":"// before\nuseQuery({ queryFn: fetchTodos })\n// after (manual)\nuseQuery({ queryKey: ['todos'], queryFn: fetchTodos })","handlingStrategy":"try-catch","validationCode":"// Pre-scan: does the options object contain the expected key property?\nfunction hasKeyProperty(objectExpr: any, keyName: string): boolean {\n  return objectExpr.properties.some((p: any) => p.key?.name === keyName)\n}","typeGuard":null,"tryCatchPattern":"try { transform(file) } catch (e) { if (/couldn't be found/.test(e.message)) missingKeyQueue.push(file) }","preventionTips":["Ensure every query options object includes the required key property before running the codemod.","Verify property names match the codemod's expectation (`queryKey`, `mutationKey`).","Run the codemod and triage cited lines manually.","Add a lint rule requiring `queryKey` on all `useQuery` calls."],"tags":["codemod","v4-migration","ast","manual-migration","query-key"],"backgroundTag":null,"analyzedSha":"159982c80b844487054155c38ffc760fe4208daf","analyzedAt":"2026-08-12T16:21:52.822Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}