remotion-dev/remotion · error · Error
Invalid JSON: ${JSON.stringify(decoded)}
Error message
Invalid JSON: ${JSON.stringify(decoded)} What it means
Thrown after UTF-8 decoding the sync response payload when JSON.parse fails. Means the function returned a body that is not valid JSON (e.g. an HTML error page, a plain string, or a truncated response). The decoded string is included via JSON.stringify.
Source
Thrown at packages/lambda-client/src/call-lambda-sync.ts:53
if (res.FunctionError) {
throw new Error(
`Lambda function returned error: ${res.FunctionError} ${res.LogResult}`,
);
}
if (!res.Payload) {
throw new Error(
`Lambda function returned no payload (status ${res.StatusCode})`,
);
}
const decoded = new TextDecoder('utf-8').decode(res.Payload);
try {
return JSON.parse(decoded) as OrError<ServerlessReturnValues<Provider>[T]>;
} catch {
throw new Error(`Invalid JSON: ${JSON.stringify(decoded)}`);
}
};
export const callFunctionSyncImplementation = async <
Provider extends CloudProvider,
T extends ServerlessRoutines,
>(
options: CallFunctionOptions<T, Provider>,
): Promise<ServerlessReturnValues<Provider>[T]> => {
const res = await callLambdaSyncWithoutRetry<T, Provider>(options);
if (res.type === 'error') {
const err = new Error(res.message);
err.stack = res.stack;
throw err;
}
return res;
};View on GitHub (pinned to 78fe4bb3fd)
Solutions
- Redeploy the Lambda function so its version matches the lambda-client version you call with
- Inspect the decoded string embedded in the error to see what non-JSON body came back
- Ensure no proxy/CDN is rewriting the Lambda response body
Defensive patterns
Strategy: try-catch
Try / catch
try {
await getCompositionsOnLambda({...});
} catch (err) {
if ((err as Error).message.startsWith('Invalid JSON:')) {
// version mismatch — redeploy the function with the current lambda-client
}
throw err;
} Prevention
- Pin and align @remotion/lambda-client and deployed function versions
- Ensure no proxy rewrites the Lambda response body
- Log the decoded non-JSON body for diagnosis
When it happens
Trigger: Sync Lambda routine whose handler returned non-JSON, or whose response was rewritten/truncated before reaching the client.
Common situations: Version mismatch between lambda-client and the deployed function (different protocol), a proxy returning its own HTML error page, partially truncated payload.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- could not parse Lambda response: %w
- could not parse Lambda progress response: %w
- Failed to parse Lambda response stream: {e}
- Failed to decode final Lambda response: {e}. Raw response: {
- Unexpected Lambda response format: {result_raw}
AI-assisted analysis of remotion-dev/remotion@78fe4bb3fd (2026-08-12).
Data as JSON: /api/errors/072a8b226850de7e.
Report an issue: GitHub.