remotion-dev/remotion · error
Could not locate the visual control value
Error message
Could not locate the visual control value
What it means
When a visualControl() call already has a second argument, the codemod must know its exact source offsets to replace it. Recast normally preserves source locations, but if the argument node lacks a .loc, no source range can be computed, so the codemod throws this error.
Solutions
- Re-parse the original source and run the codemod on a freshly parsed AST
- Reformat the file (prettier) and retry so the argument exists as real source text
- Replace the value manually if locations cannot be recovered
Example fix
null
Defensive patterns
Strategy: try-catch
Validate before calling
const hasLocatedArgs = (node: any) => node.arguments[1] && node.arguments[1].loc !== undefined;
Type guard
const hasLoc = (n: {loc?: unknown}): n is {loc: NonNullable<unknown>} => n.loc != null; Try / catch
try {
applyVisualControl({input, transformation});
} catch (e) {
if ((e as Error).message.includes('Could not locate the visual control value')) {
input = format(input); // reparse + retry
applyVisualControl({input, transformation});
}
} Prevention
- Run codemods on freshly parsed source, not on recast-printed/re-parsed intermediate ASTs
- Avoid chaining transformations that synthesize visualControl call nodes
- Persist to disk and reformat between chained codemod steps
When it happens
Trigger: Visiting a visualControl() call whose node.arguments[1] exists but has loc === undefined — typically because the AST was transformed/generated by recast (e.g. prior codemods inserted the node) rather than parsed directly from source.
Common situations: Chaining codemods on the same file where an earlier step programmatically built the visualControl() call; parsing/printing round-trips that drop location info.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- Could not locate the visual control identifier
- Cannot duplicate a JSX element without a source location
- Cannot duplicate JSX element with no parent
- Cannot split a JSX sequence without a source location
- Cannot split audio from a JSX element with no parent
AI-assisted analysis of remotion-dev/remotion@46a3a6bf13 (2026-09-18).
Data as JSON: /api/errors/d19b246d8296f749.
Report an issue: GitHub.
Appendix: source
Thrown at packages/studio-codemods/src/apply-visual-control.ts:89
const change = matchingChanges.at(-1);
if (!change) {
return this.traverse(path);
}
const serialized = change.newValueIsUndefined
? 'undefined'
: stringifyDefaultProps({
props: JSON.parse(change.newValueSerialized),
enumPaths: change.enumPaths,
});
if (serialized === undefined) {
throw new Error('Could not serialize the visual control value');
}
const secondArgument = node.arguments[1];
if (secondArgument) {
if (!secondArgument.loc) {
throw new Error('Could not locate the visual control value');
}
const start = recastLocToOffset(input, secondArgument.loc.start);
const end = recastLocToOffset(input, secondArgument.loc.end);
const lineStart = input.lastIndexOf('\n', start - 1) + 1;
edits.push({
start,
end,
replacement: formatSerializedValue({
input,
linePrefix: input.slice(lineStart, start),
previousValue: input.slice(start, end).trim(),
serialized,
}),
});
} else {
if (!firstArgument.loc) {
throw new Error('Could not locate the visual control identifier');View on GitHub (pinned to 46a3a6bf13)