remotion-dev/remotion · error

Cannot paste effects: invalid insertion indices

Error message

Cannot paste effects: invalid insertion indices

What it means

When pasting copied effects with explicit insert positions, insertAtIndices is only valid for type 'effects-additive' and must contain exactly one unique, non-negative integer per pasted effect. If insertAtIndices is non-null but any of these conditions fails, the paste is rejected with this error before any AST mutation.

Solutions

  1. Only pass insertAtIndices when type is 'effects-additive'; pass null otherwise.
  2. Ensure insertAtIndices.length === effects.length with no duplicates.
  3. Sanitize indices: Number.isInteger(i) && i >= 0 for every entry.
  4. Regenerate indices from the current target element's effect count.

Example fix

// before
await pasteEffects({input, effects, type: 'effects-replacing', insertAtIndices: [0]});
// after
await pasteEffects({input, effects, type: 'effects-replacing', insertAtIndices: null});
Defensive patterns

Strategy: validation

Validate before calling

if (insertAtIndices !== null) {
  const ok = type === 'effects-additive' &&
    insertAtIndices.length === effects.length &&
    new Set(insertAtIndices).size === insertAtIndices.length &&
    insertAtIndices.every((i) => Number.isInteger(i) && i >= 0);
  if (!ok) throw new Error('Bad insertAtIndices');
}

Type guard

const isValidInsertIndices = (idx: unknown[] | null, n: number): idx is number[] =>
  idx !== null && idx.length === n &&
  new Set(idx).size === idx.length &&
  idx.every((i) => Number.isInteger(i) && i >= 0);

Try / catch

try {
  await pasteEffects(args);
} catch (e) {
  if (e instanceof Error && e.message === 'Cannot paste effects: invalid insertion indices') {
    // fall back to append: insertAtIndices: null
  } else throw e;
}

Prevention

When it happens

Trigger: Calling pasteEffects with type 'effects-replacing' (or anything other than 'effects-additive') while also passing insertAtIndices; passing a different number of indices than effects; duplicate indices; negative or non-integer indices like -1, 1.5, NaN.

Common situations: UI paste handler that always supplies insertAtIndices from drag metadata even when the paste mode is 'replace'; mismatch between clipboard effect count and drop-slot count; index math producing fractional values.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of remotion-dev/remotion@46a3a6bf13 (2026-09-18). Data as JSON: /api/errors/4280f2d3d72228b9. Report an issue: GitHub.

Appendix: source

Thrown at packages/studio-codemods/src/effect-operations.ts:881

			ensureFrameHook({
				ast,
				localNames,
				sequenceNodePath: targetSequenceNodePath,
			});
		}

		const calls = effects.map((effect) =>
			makeEffectCall({ast, effect, localNames}),
		);
		const existingAttr = findEffectsAttr(jsx.attributes);
		if (
			insertAtIndices !== null &&
			(type !== 'effects-additive' ||
				insertAtIndices.length !== calls.length ||
				new Set(insertAtIndices).size !== insertAtIndices.length ||
				insertAtIndices.some((index) => !Number.isInteger(index) || index < 0))
		) {
			throw new Error('Cannot paste effects: invalid insertion indices');
		}

		if (type === 'effects-replacing') {
			if (existingAttr) {
				jsx.attributes.splice(jsx.attributes.indexOf(existingAttr), 1);
			}

			if (calls.length > 0) {
				jsx.attributes.push(
					makeEffectsAttr(b.arrayExpression(calls as never) as ArrayExpression),
				);
			}
		} else if (calls.length === 0) {
			throw new Error('Cannot paste effects: no effects were copied');
		} else if (insertAtIndices === null) {
			if (existingAttr) {
				getEffectsArray(existingAttr, 'paste').elements.push(
					...(calls as ArrayExpression['elements']),

View on GitHub (pinned to 46a3a6bf13)