remotion-dev/remotion · error · TypeError

trimAfter must be a positive number, instead got ${trimAfter

Error message

trimAfter must be a positive number, instead got ${trimAfter}.

What it means

trimAfter specifies the frame at which playback stops, and it must be strictly positive (greater than 0). validateTrimProps rejects zero and negative values because an end frame of 0 or below means the media would never play.

Source

Thrown at packages/core/src/validate-start-from-props.ts:80

			throw new TypeError(
				`trimBefore must be greater than equal to 0 instead got ${trimBefore}.`,
			);
		}
	}

	if (typeof trimAfter !== 'undefined') {
		if (typeof trimAfter !== 'number') {
			throw new TypeError(
				`type of trimAfter prop must be a number, instead got type ${typeof trimAfter}.`,
			);
		}

		if (isNaN(trimAfter)) {
			throw new TypeError('trimAfter prop can not be NaN.');
		}

		if (trimAfter <= 0) {
			throw new TypeError(
				`trimAfter must be a positive number, instead got ${trimAfter}.`,
			);
		}
	}

	if ((trimAfter as number) <= (trimBefore as number)) {
		throw new TypeError('trimAfter prop must be greater than trimBefore prop.');
	}
};

export const validateMediaTrimProps = ({
	startFrom,
	endAt,
	trimBefore,
	trimAfter,
}: {
	startFrom: number | undefined;
	endAt: number | undefined;

View on GitHub (pinned to 78fe4bb3fd)

Solutions

  1. Pass a positive frame number: trimAfter={200}.
  2. Clamp the computed value to at least 1: trimAfter={Math.max(1, computed)}.
  3. Verify the duration math that produces trimAfter; ensure the source media is long enough.

Example fix

// before
<Video src={src} trimAfter={duration - margin} /> // can be <= 0
// after
<Video src={src} trimAfter={Math.max(1, duration - margin)} />
Defensive patterns

Strategy: validation

Validate before calling

if (trimAfter !== undefined && trimAfter <= 0) {
  throw new Error('trimAfter must be > 0');
}

Type guard

const isValidTrimAfter = (v: unknown): v is number =>
  typeof v === 'number' && !Number.isNaN(v) && v > 0;

Prevention

When it happens

Trigger: Passing trimAfter={0}, trimAfter={-5}, or a computed expression that evaluates to zero or a negative number.

Common situations: Setting trimAfter to 0 by mistake (e.g. defaulting an uninitialized variable to 0); subtracting a margin that drives the end before frame 0; off-by-one when trimAfter is computed from a duration that collapses to 0.

Related errors


AI-assisted analysis of remotion-dev/remotion@78fe4bb3fd (2026-08-12). Data as JSON: /api/errors/101df053919cf4a6. Report an issue: GitHub.