remotion-dev/remotion · error

Could not find target folder

Error message

Could not find target folder

What it means

moveCompositionToFolder moves a composition into a target folder (or to root when no folder is given). After the AST walk, if the destination was specified but the target folder element could not be found, this defensive check throws before attempting to append the composition to a null folder element.

Source

Thrown at packages/studio-codemods/src/recast-mods.ts:845

	if (transformation.folderName !== null && !targetFolder) {
		const folderLabel = `${transformation.parentName ? `${transformation.parentName}/` : ''}${transformation.folderName}`;
		throw new Error(`Could not find folder "${folderLabel}"`);
	}

	const compositionElement = (sourcePath as recast.types.NodePath)
		.node as JSXElement;
	const sourceReturnStatement = getEnclosingReturnStatement(sourcePath);
	deleteJsxElementAtPath(sourcePath);
	if (transformation.folderName === null) {
		appendElementToRoot({
			element: compositionElement,
			returnStatement: sourceReturnStatement,
		});
		changesMade.push({description: 'Moved composition to root'});
	} else {
		if (targetFolder === null) {
			throw new Error('Could not find target folder');
		}

		appendElementToFolder({
			element: compositionElement,
			folderElement: targetFolder,
		});
		changesMade.push({description: 'Moved composition into folder'});
	}

	return {newAst: file, changesMade};
};

// When a <Composition> JSX element appears in a position where it cannot
// simply be removed from a parent's children list (e.g. as the sole return
// value of a wrapper component or as the concise body of an arrow function),
// we still want delete/rename/duplicate codemods to work. This helper detects
// that case and produces a structurally-valid replacement expression.
const transformLoneJsxElement = (

View on GitHub (pinned to a6a7485a9a)

Solutions

  1. Verify the target folder element exists in the file before invoking the codemod
  2. Regenerate the transformation from current composition state
  3. Fall back to moving the composition to root, or create the folder first

Example fix

// before
moveToFolder({composition: 'MyComp', folder: 'OldFolderName'});
// after
moveToFolder({composition: 'MyComp', folder: 'CurrentFolderName'});
Defensive patterns

Strategy: validation

Validate before calling

const target = findFolderElement(ast, folderName);
if (!target) throw new Error(`Folder "${folderName}" not found; cannot move composition`);

Try / catch

try {
  await applyCodemod({transformation});
} catch (e) {
  if (String(e) === 'Error: Could not find target folder') {
    await applyCodemod({transformation: {...transformation, destination: {type: 'root'}}}); // fallback to root
  } else throw e;
}

Prevention

When it happens

Trigger: Calling applyCodemod with a move-to-folder transformation where the named target folder does not exist in the composition file — the folder was deleted, renamed, or the name/parent does not match any <Folder> element.

Common situations: Stale studio folder state; typo in the folder name passed by a script or studio UI; folder lives in another composition file.

Related errors


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