{"record":{"id":"3355006d2f2694b4","repo":"facebook/flow","slug":"updatependingstatements-variable-parent-of-dep","errorCode":null,"errorMessage":"updatePendingStatements: Variable parent of \"${dep}\" not found","messagePattern":"updatePendingStatements: Variable parent of \"(.+?)\" not found","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/flow-api-translator/src/flowToFlowDef.js","lineNumber":425,"sourceCode":"  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  }\n  function updateProcessedStatement(stmt: ProgramStatement): void {\n    processedStatements.add(stmt);\n    pendingStatements.delete(stmt);\n  }\n\n  // Process all export statements\n  for (const stmt of ast.body) {","sourceCodeStart":407,"sourceCodeEnd":443,"githubUrl":"https://github.com/facebook/flow/blob/21c11b2eada01107bc3a459b0e99a7e56a502ddc/packages/flow-api-translator/src/flowToFlowDef.js#L407-L443","documentation":"Companion to error 3 in the same loop: the dependency's Variable was found in context.variableMap, but one of its scope definitions has def.node == null, so translation cannot locate the AST statement that defines it and throws. It indicates the variable exists in the module scope without an attached defining node (implicit/ambient definitions rather than a concrete declaration).","triggerScenarios":"translateFlowToFlowDef input whose dependency resolves to a module-scope Variable whose defs array contains a Definition with a null node (implicit globals, injected builtins like require/module, or scope-analysis artifacts), so getTopLevelStatement has no statement to enqueue.","commonSituations":"Converting files that use CommonJS injected names (require, module, exports) or ambient implicit globals as dependencies of exported declarations; scope-manager versions whose Definition.node is optional for some def types.","solutions":["Replace reliance on implicit globals with explicit declarations (`declare var require: any;` style) or imports in the input file.","Run with recoverFromErrors: true to let the translator emit error comments and continue.","Isolate the dependency named in the message and inspect how it is defined; rewrite it as a normal top-level declaration.","Report the repro upstream if the definition is a plain top-level statement, since def.node should then be set."],"exampleFix":"// before\nexports.make = () => require('./util'); // implicit module/require\n\n// after\nimport util from './util';\nexport const make = () => util;","handlingStrategy":"try-catch","validationCode":"// Detect dependencies whose defs lack a defining node before translating\nfunction depsWithMissingDefNode(context, deps) {\n  return deps.filter((d) => {\n    const v = context.variableMap.get(d);\n    return v == null || v.defs.some((def) => def.node == null);\n  });\n}","typeGuard":"function hasConcreteDefs(variable) {\n  return variable != null && variable.defs.length > 0 && variable.defs.every((d) => d.node != null);\n}","tryCatchPattern":"try {\n  const {code: out} = await translateFlowToFlowDef({code, recoverFromErrors: true});\n} catch (e) {\n  const m = /Variable parent of \"(.+)\" not found/.exec(e.message);\n  if (m) {\n    report(`\"${m[1]}\" resolves to an implicit/ambient definition — rewrite it as an explicit top-level declaration`);\n    return;\n  }\n  throw e;\n}","preventionTips":["Avoid implicit globals (require/module/exports, UMD React) as dependencies of exported declarations.","Convert CommonJS usage to ESM imports before extracting libdefs.","Enable recoverFromErrors in batch tooling and log the dependency name from the message."],"tags":["flow","api-translator","libdef","scope","implicit-globals"],"backgroundTag":"missing-variable-definition","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"}