remotion-dev/remotion · error · Error

Expected an in-memory output target

Error message

Expected an in-memory output target

What it means

Thrown in finalize() when the output is in default (in-memory) mode but the mediabunny output's target is not a BufferTarget, so no blob can be read from memory. The wrapper requires an in-memory BufferTarget to expose getBlob().

Source

Thrown at packages/video-matting/src/create-video-layer-output.ts:269

					let blobPromise: Promise<Blob> | null = null;

					return {
						dispose: discard,
						getBlob: () => {
							blobPromise ??= (async () => {
								const file = await webFsTarget.getBlob();
								const buffer = await file.arrayBuffer();
								return new Blob([buffer], {type: mimeType});
							})();

							return blobPromise;
						},
					};
				}

				if (!(target instanceof BufferTarget)) {
					throw new Error('Expected an in-memory output target');
				}

				return {
					dispose: () => Promise.resolve(),
					getBlob: () => {
						if (target.buffer === null) {
							return Promise.reject(new Error('The resulting buffer is empty'));
						}

						return Promise.resolve(new Blob([target.buffer], {type: mimeType}));
					},
				};
			} catch (error) {
				await Promise.allSettled([cancelMediabunnyOutput(), discard()]);
				throw error;
			}
		})();

View on GitHub (pinned to b2f4e34732)

Solutions

  1. Construct the mediabunny Output with new BufferTarget() when you intend to read the result via getBlob()
  2. Or switch the layer output to 'writable'/'web-fs' mode to match the actual target
  3. Inspect output.target instanceof BufferTarget before finalizing

Example fix

// before
const output = new Output({target: new StreamTarget(stream)});
const blob = await createVideoLayerOutput({output}).finalize();
// after
const output = new Output({target: new BufferTarget()});
const blob = await createVideoLayerOutput({output}).finalize();
Defensive patterns

Strategy: type-guard

Validate before calling

import {BufferTarget} from 'mediabunny';
if (!(output.target instanceof BufferTarget)) {
  throw new Error('getBlob() requires a BufferTarget');
}

Type guard

const isInMemory = (output: {target: unknown}): output is {target: BufferTarget} =>
  output.target instanceof BufferTarget;

Try / catch

try {
  await layerOutput.finalize();
} catch (e) {
  if ((e as Error).message === 'Expected an in-memory output target') {
    // switch to writable/web-fs mode or re-create output with BufferTarget
  }
  throw e;
}

Prevention

When it happens

Trigger: Creating the output without outputMode 'writable'/'web-fs' but attaching a StreamTarget or custom target instead of BufferTarget.

Common situations: Copy-pasted Output configuration from a streaming example; a refactor switched to StreamTarget for progress but getBlob() is still expected; target passed as null.

Understand the failure class

Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.

Related errors


AI-assisted analysis of remotion-dev/remotion@b2f4e34732 (2026-09-09). Data as JSON: /api/errors/d705340c71f85510. Report an issue: GitHub.