{"record":{"id":"66448b9d11101f5a","repo":"facebook/flow","slug":"updatependingstatements-variable-for-dependency","errorCode":null,"errorMessage":"updatePendingStatements: Variable for dependency \"${dep}\" not found","messagePattern":"updatePendingStatements: Variable for dependency \"(.+?)\" not found","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/flow-api-translator/src/flowToFlowDef.js","lineNumber":418,"sourceCode":"  function storeTranslatedStatement(\n    stmt: DetachedNode<ProgramStatement>,\n    orgStmt: ProgramStatement,\n  ): void {\n    translatedStatements.set(orgStmt, stmt);\n  }\n\n  const seenDeps = new Set<Dep>();\n  const processedStatements = new Set<ProgramStatement>();\n  const pendingStatements = new Set<ProgramStatement>();\n  function updatePendingStatements(deps: TranslatedDeps): void {\n    for (const dep of deps) {\n      if (seenDeps.has(dep)) {\n        continue;\n      }\n      seenDeps.add(dep);\n      const variable = context.variableMap.get(dep);\n      if (variable == null) {\n        throw new Error(\n          `updatePendingStatements: Variable for dependency \"${dep}\" not found`,\n        );\n      }\n      for (const def of variable.defs) {\n        const stmt = def.node;\n        if (stmt == null) {\n          throw new Error(\n            `updatePendingStatements: Variable parent of \"${dep}\" not found`,\n          );\n        }\n        const topLevelStmt = getTopLevelStatement(stmt, context);\n        if (processedStatements.has(topLevelStmt)) {\n          continue;\n        }\n        pendingStatements.add(topLevelStmt);\n      }\n    }\n  }","sourceCodeStart":400,"sourceCodeEnd":436,"githubUrl":"https://github.com/facebook/flow/blob/21c11b2eada01107bc3a459b0e99a7e56a502ddc/packages/flow-api-translator/src/flowToFlowDef.js#L400-L436","documentation":"During flowToFlowDef translation, every dependency name collected from a translated statement is looked up in context.variableMap, which createTranslationContext populated from module-scope variables only. If a dependency name has no entry, the name was never a module-scope variable (unresolved reference, global, or name from a non-module scope) and translation aborts with this error.","triggerScenarios":"Calling translateFlowToFlowDef on code whose exported/translated statements reference identifiers that are not declared or imported at module scope: bare globals used as types (e.g. JSX, React without import), references inside `declare module` bodies, or names that only exist in an outer/nested scope. recoverFromErrors does not cover this raw throw.","commonSituations":"Extracting libdefs from files that rely on ambient globals (React UMD global, JSX namespace) without imports; converting partial files that reference symbols defined in another file; incremental libdef extraction tooling hitting unimported references.","solutions":["Add explicit imports or `declare var/function/type` statements for every referenced-but-undeclared identifier in the input file.","Run the translator with recoverFromErrors: true so unsupported constructs degrade into error comments instead of aborting, then fix flagged inputs.","Reduce the input to the failing declaration (the message names the dependency) and add the missing module-scope definition.","If the dependency is a global, declare it: `declare var React: any;` at module level."],"exampleFix":"// before\nexport const element = <div />; // React not imported\n\n// after\nimport * as React from 'react';\nexport const element = <div />;","handlingStrategy":"try-catch","validationCode":"// Check every referenced top-level identifier in input has a module-scope binding\nimport {analyze} from 'flow-eslint-scope'; // conceptually\nfunction unboundModuleNames(ast, scopeManager) {\n  const mod = scopeManager.globalScope.childScopes[0];\n  const bound = new Set(mod.variables.map((v) => v.name));\n  const unresolved = new Set();\n  walk(ast, (n) => {\n    if (n.type === 'Identifier' && !bound.has(n.name)) unresolved.add(n.name);\n  });\n  return [...unresolved];\n}","typeGuard":"function isModuleScopeVariableName(context, name) {\n  return context.variableMap.has(name);\n}","tryCatchPattern":"try {\n  const {code: out} = await translateFlowToFlowDef({code, recoverFromErrors: true});\n} catch (e) {\n  const m = /Variable for dependency \"(.+)\" not found/.exec(e.message);\n  if (m) {\n    report(`add an import or declare for \"${m[1]}\" in the input, then retry`);\n    return;\n  }\n  throw e;\n}","preventionTips":["Import every symbol the exported code references, including React for JSX.","Declare ambient globals explicitly (declare var/type) instead of relying on them.","Run with recoverFromErrors: true so gaps degrade to comments; parse the dependency name out of the message to auto-fix."],"tags":["flow","api-translator","libdef","scope","dependency-resolution"],"backgroundTag":"unresolved-identifier","analyzedSha":"21c11b2eada01107bc3a459b0e99a7e56a502ddc","analyzedAt":"2026-08-20T10:41:37.992Z","contentChangedAt":"2026-08-20T10:41:37.992Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}