remotion-dev/remotion · error · TypeError

`maxSize` must be a number greater than 0

Error message

`maxSize` must be a number greater than 0

What it means

Thrown by the LRU cache constructor vendored into @remotion/gif when `options.maxSize` is falsy or not greater than zero. The cache requires a positive capacity at construction time; any value that fails `options.maxSize && options.maxSize > 0` (0, negative numbers, NaN, undefined, null) triggers this TypeError.

Source

Thrown at packages/gif/src/lru/index.ts:85

	@example
	```
	import { QuickLRU } from 'quick-lru-ts';

	const lru = new QuickLRU({maxSize: 1000});

	lru.set('🦄', '🌈');

	lru.has('🦄');
	//=> true

	lru.get('🦄');
	//=> '🌈'
	```
	*/
	constructor(options: Options<KeyType, ValueType>) {
		if (!(options.maxSize && options.maxSize > 0)) {
			throw new TypeError('`maxSize` must be a number greater than 0');
		}

		if (typeof options.maxAge === 'number' && options.maxAge === 0) {
			throw new TypeError('`maxAge` must be a number greater than 0');
		}

		this.maxSize = options.maxSize;
		this.maxAge = options.maxAge || Number.POSITIVE_INFINITY;
		this.onEviction = options.onEviction;
		this.cache = new Map();
		this.oldCache = new Map();
		this._size = 0;
	}

	private _emitEvictions(
		cache: Map<KeyType, MapValue<ValueType>> | [KeyType, MapValue<ValueType>][],
	) {
		if (typeof this.onEviction !== 'function') {

View on GitHub (pinned to 78fe4bb3fd)

Solutions

  1. Pass a positive integer for `maxSize`, e.g. `new LRUCache({maxSize: 100})`.
  2. If `maxSize` is dynamic, coerce and clamp it before construction: `Math.max(1, Math.floor(value))`.
  3. Ensure the options object always includes `maxSize`.

Example fix

// before
const cache = new LRUCache({maxSize: Number(process.env.CACHE_SIZE)});

// after
const cache = new LRUCache({
  maxSize: Math.max(1, Number(process.env.CACHE_SIZE) || 50),
});
Defensive patterns

Strategy: validation

Validate before calling

function makeCache(maxSize: number) {
  if (!Number.isFinite(maxSize) || maxSize <= 0) {
    throw new Error(`maxSize must be a positive integer, got ${maxSize}`);
  }
  return new LRUCache({maxSize: Math.floor(maxSize)});
}

Type guard

function isValidMaxSize(value: unknown): value is number {
  return typeof value === 'number' && Number.isFinite(value) && value > 0;
}

Prevention

When it happens

Trigger: Constructing `new LRUCache({maxSize: 0})`, `new LRUCache({maxSize: -1})`, `new LRUCache({maxSize: NaN})`, or omitting `maxSize` entirely. The check uses truthiness, so `0` is rejected because an empty cache is meaningless.

Common situations: Deriving `maxSize` from an environment variable or config that defaults to 0; passing a computed size that underflows to a negative; refactoring that drops the `maxSize` field from the options object.

Related errors


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