facebook/flow · error · Error
updatePendingStatements: Variable for dependency "${dep}" no
Error message
updatePendingStatements: Variable for dependency "${dep}" not found What it means
Internal invariant in flowToFlowDef (flow-api-translator). While ordering top-level output statements it walks each translated statement's dependencies and looks each name up in context.variableMap. If a dependency identifier has no Variable record, translation state is inconsistent and it throws, naming the dependency.
Source
Thrown at packages/flow-api-translator/src/flowToFlowDef.js:191
function storeTranslatedStatement(
stmt: DetachedNode<ProgramStatement>,
orgStmt: ProgramStatement,
): void {
translatedStatements.set(orgStmt, stmt);
}
const seenDeps = new Set<Dep>();
const processedStatements = new Set<ProgramStatement>();
const pendingStatements = new Set<ProgramStatement>();
function updatePendingStatements(deps: TranslatedDeps): void {
for (const dep of deps) {
if (seenDeps.has(dep)) {
continue;
}
seenDeps.add(dep);
const variable = context.variableMap.get(dep);
if (variable == null) {
throw new Error(
`updatePendingStatements: Variable for dependency "${dep}" not found`,
);
}
for (const def of variable.defs) {
const stmt = def.node;
if (stmt == null) {
throw new Error(
`updatePendingStatements: Variable parent of "${dep}" not found`,
);
}
const topLevelStmt = getTopLevelStatement(stmt, context);
if (processedStatements.has(topLevelStmt)) {
continue;
}
pendingStatements.add(topLevelStmt);
}
}
}View on GitHub (pinned to d1341dac89)
Solutions
- Pass a complete Program AST (all statements of the file) — fragments leave referenced identifiers undeclared
- Declare or import the identifier named in the message inside the input source so it resolves within the same program
- Update flow-api-translator in case the lookup logic changed for your AST shape
- Minimize the input and file an issue — this is a violated translator invariant
Defensive patterns
Strategy: validation
Validate before calling
// Before translating, ensure every referenced identifier is declared
// within the same Program you pass in.
function collectDeclared(program: {body: any[]}): Set<string> {
const declared = new Set<string>();
for (const stmt of program.body) {
switch (stmt.type) {
case 'VariableDeclaration':
for (const d of stmt.declarations) declared.add(d.id.name);
break;
case 'FunctionDeclaration':
case 'ClassDeclaration':
case 'TypeAlias':
case 'InterfaceDeclaration':
if (stmt.id) declared.add(stmt.id.name);
break;
case 'ImportDeclaration':
for (const s of stmt.specifiers) declared.add(s.local.name);
break;
}
}
return declared;
}
// then: referencedNames ⊆ declared ∪ FLOW_GLOBALS before calling translate Try / catch
try {
const defs = translateFlowASTToFlowDef(program, context);
} catch (err) {
if (err instanceof Error && err.message.includes('Variable for dependency')) {
// undeclared/global identifier: log program.body statement types and move on
} else throw err;
} Prevention
- Translate whole files, never fragments or hand-pruned ASTs
- Ensure the input source passes `flow check` first
- Use the parser output directly without cloning or transform passes
When it happens
Trigger: Translating a Flow AST program where a statement references an identifier never registered in the translation context's variableMap — an undeclared/global identifier, a name imported or declared outside the supplied statements, a partial Program AST, or an AST missing scope/parent information.
Common situations: Feeding hand-built, cloned, or subtree ASTs into the translator instead of a full Program; identifiers that are Flow builtins or globals not declared in the input file; translator/parser version mismatch dropping scope info.
Related errors
- updatePendingStatements: Variable parent of "${dep}" not fou
- Unexpected function parameter ${param.type}
- Flow check failed!
- Flow version ${version} doesn't support 'flow lsp'. Please u
- Unsupported .flowconfig option `log.file`. The VS Code exten
AI-assisted analysis of facebook/flow@d1341dac89 (2026-08-17).
Data as JSON: /api/errors/66448b9d11101f5a.
Report an issue: GitHub.