remotion-dev/remotion · error · TypeError

parameter 'memorySizeInMb' must be finite, but is ${memorySi

Error message

parameter 'memorySizeInMb' must be finite, but is ${memorySizeInMb}

What it means

Thrown by validateMemorySize() when memorySizeInMb is a non-finite number, i.e. Infinity or -Infinity. AWS Lambda cannot allocate infinite memory; valid sizes are integers in [512, 10240] MB. The guard sits after the NaN check, so only Infinity/-Infinity reaches this branch.

Source

Thrown at packages/lambda-client/src/validate-memory-size.ts:15

import {MAX_MEMORY, MIN_MEMORY} from './constants';

export const validateMemorySize = (memorySizeInMb: unknown) => {
	if (typeof memorySizeInMb !== 'number') {
		throw new TypeError(
			`parameter 'memorySizeInMb' must be a number, got a ${typeof memorySizeInMb}`,
		);
	}

	if (Number.isNaN(memorySizeInMb)) {
		throw new TypeError(`parameter 'memorySizeInMb' must not be NaN, but is`);
	}

	if (!Number.isFinite(memorySizeInMb)) {
		throw new TypeError(
			`parameter 'memorySizeInMb' must be finite, but is ${memorySizeInMb}`,
		);
	}

	if (memorySizeInMb < MIN_MEMORY || memorySizeInMb > MAX_MEMORY) {
		throw new TypeError(
			`parameter 'memorySizeInMb' must be between ${MIN_MEMORY} and ${MAX_MEMORY}, but got ${memorySizeInMb}`,
		);
	}

	if (memorySizeInMb % 1 !== 0) {
		throw new TypeError(
			`parameter 'memorySizeInMb' must be an integer but got ${memorySizeInMb}`,
		);
	}
};

View on GitHub (pinned to 78fe4bb3fd)

Solutions

  1. Clamp the computed value with Math.min(Math.max(value, 512), 10240) so Infinity is capped before validation.
  2. Reject non-finite inputs at the source using Number.isFinite() and substitute DEFAULT_MEMORY_SIZE (2048).
  3. Audit the formula producing memorySizeInMb for divisions by zero or unbounded multipliers.

Example fix

// before
const memorySizeInMb = maxFrames / 0; // Infinity
await renderMediaOnLambda({memorySizeInMb, ...});

// after
const raw = maxFrames / divisor;
const memorySizeInMb = Number.isFinite(raw) ? Math.min(Math.max(Math.round(raw), 512), 10240) : 2048;
await renderMediaOnLambda({memorySizeInMb, ...});
Defensive patterns

Strategy: type-guard

Validate before calling

const safeMemory = (v: unknown): number => {
  const n = Number(v);
  return Number.isFinite(n) ? Math.min(Math.max(Math.round(n), 512), 10240) : 2048;
};

Type guard

const isMemorySize = (v: unknown): v is number =>
  typeof v === 'number' && Number.isFinite(v) && v >= 512 && v <= 10240 && v % 1 === 0;

Prevention

When it happens

Trigger: Passing memorySizeInMb derived from Number('Infinity'), parseFloat('Infinity'), or an overflowing arithmetic expression (e.g. a huge divisor collapse). Also from a formula like maxMemory * factor where factor is unbounded.

Common situations: A config UI that lets the user type 'Infinity', an env var containing that literal, or a calculation that divides by zero yielding Infinity after rounding.

Related errors


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