remotion-dev/remotion · error · Error

Could not parse the serialized value

Error message

Could not parse the serialized value

What it means

formatSerializedValue wraps a serialized value as `__value = <serialized>` and parses it with the Babel parser, expecting an ExpressionStatement containing an AssignmentExpression whose right side is the value. If the string fails to parse or produces a different AST shape, the function cannot extract the value and throws this error.

Solutions

  1. Log and inspect the serialized string; ensure it is a complete, valid JS expression (e.g. JSON.stringify output of an object/array/number).
  2. Re-generate the serialized value from the original data instead of round-tripping a possibly edited string.
  3. Validate with a quick parse check (e.g. JSON.parse for JSON values) before calling formatSerializedValue.
  4. If values are intentionally non-JSON JS literals, ensure they are still parser-valid (quote keys correctly, no trailing commas).

Example fix

// before (truncated)
formatSerializedValue('{"a": 1, "b"'); // throws
// after
const serialized = JSON.stringify({a: 1, b: 2});
JSON.parse(serialized); // sanity check
formatSerializedValue(serialized); // ok
Defensive patterns

Strategy: validation

Validate before calling

function assertSerializable(s: string): string {
  try { JSON.parse(s); } catch { throw new Error('Serialized value is not valid JSON: ' + s.slice(0, 50)); }
  return s;
}
formatSerializedValue(assertSerializable(serialized));

Try / catch

try {
  formatSerializedValue(serialized);
} catch (e) {
  if (e instanceof Error && e.message === 'Could not parse the serialized value') {
    console.error('Bad serialized input:', serialized);
    serialized = JSON.parse(originalData);
  } else throw e;
}

Prevention

When it happens

Trigger: Passing a string that is not a syntactically valid JS expression literal to formatSerializedValue — e.g. truncated JSON, JSON5/JS-only syntax the parser rejects, or text that parses but is not an assignment-shaped statement.

Common situations: Serializing studio props/visual-control values with a custom serializer that emits invalid or truncated output; double-encoding values (JSON string of a string); clipboard-edited values pasted with stray characters.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of remotion-dev/remotion@46a3a6bf13 (2026-09-18). Data as JSON: /api/errors/05e9fe7eb92002da. Report an issue: GitHub.

Appendix: source

Thrown at packages/studio-codemods/src/format-serialized-value.ts:46

				? true
				: previousValue.startsWith('{') &&
					  !previousValue.startsWith('{\n') &&
					  !previousValue.startsWith('{\r\n')
					? false
					: inlineObjectSpacing === undefined
						? null
						: inlineObjectSpacing.length > 0;
	const formattingConfig = getSourceFormattingConfig({
		input,
		prettierConfigOverride: bracketSpacing === null ? null : {bracketSpacing},
	});
	const valueAst = parseAst(`__value = ${serialized}`);
	const statement = valueAst.program.body[0];
	if (
		statement?.type !== 'ExpressionStatement' ||
		statement.expression.type !== 'AssignmentExpression'
	) {
		throw new Error('Could not parse the serialized value');
	}

	const expression = statement.expression.right;
	recast.types.visit(expression, {
		visitObjectProperty(path) {
			const {node} = path;
			if (
				!node.computed &&
				node.key.type === 'StringLiteral' &&
				identifierRegex.test(node.key.value)
			) {
				node.key = recast.types.builders.identifier(node.key.value);
			}

			this.traverse(path);
		},
	});

View on GitHub (pinned to 46a3a6bf13)