remotion-dev/remotion · error · Error
Unknown fit: ${fit}
Error message
Unknown fit: ${fit} What it means
calculateImageFit computes source/destination rectangles for drawing an image into a canvas for the 'contain', 'cover', and 'fill' strategies. The switch is intended to be exhaustive over the ImageFit union; the default branch throws to surface any value that escapes the union (typically via TypeScript escape hatches).
Source
Thrown at packages/core/src/calculate-image-fit.ts:70
canvasSize.height / imageSize.height,
);
const centerX = (canvasSize.width - imageSize.width * ratio) / 2;
const centerY = (canvasSize.height - imageSize.height * ratio) / 2;
return [
0,
0,
imageSize.width,
imageSize.height,
centerX,
centerY,
imageSize.width * ratio,
imageSize.height * ratio,
];
}
default:
throw new Error('Unknown fit: ' + fit);
}
};
View on GitHub (pinned to 78fe4bb3fd)
Solutions
- Use one of the supported values: 'contain', 'cover', or 'fill'.
- If accepting user/config input, validate against an allowlist before calling.
- Map unsupported fit values to the closest supported one at the boundary.
Example fix
// before
calculateImageFit('scale-to-fill' as ImageFit, img, canvas)
// after
calculateImageFit('fill', img, canvas) Defensive patterns
Strategy: type-guard
Validate before calling
const ALLOWED_FITS = new Set(['contain', 'cover', 'fill']);
if (!ALLOWED_FITS.has(fit)) {
fit = 'contain'; // or throw your own error
} Type guard
const isImageFit = (v: unknown): v is 'contain' | 'cover' | 'fill' => v === 'contain' || v === 'cover' || v === 'fill';
Prevention
- Validate external/config fit strings against the allowlist at the boundary.
- Avoid `as ImageFit` casts on untrusted values.
- Map unsupported fit vocabulary to the closest supported option.
When it happens
Trigger: Calling calculateImageFit('crop', ...) or calculateImageFit('scale-to-fill', ...). Usually reached by casting a string to ImageFit via 'as any'/'as ImageFit' or by passing user input that wasn't validated against the allowed set.
Common situations: Integrating a design tool's fit vocabulary (which has more options than Remotion supports); passing a runtime string from a config file; copy-pasting a fit value from another library.
Related errors
- inputRange must contain only numbers
- outputStyles must contain only objects
- Argument passed to "${api}" for param "${param}" is undefine
- setImageSequence accepts a Boolean Value
- outputLocation must be a string but got ${typeof newOutputLo
AI-assisted analysis of remotion-dev/remotion@78fe4bb3fd (2026-08-12).
Data as JSON: /api/errors/ba37ab8e4371a628.
Report an issue: GitHub.