remotion-dev/remotion · error

A folder named "${sourceFolderName}" already exists in the d

Error message

A folder named "${sourceFolderName}" already exists in the destination

What it means

When moving a folder to a destination parent, the codemod checks the destination for a different folder element with the same folder name. If such a sibling folder already exists there (excluding the source folder itself), the move would produce two folders with the same name under one parent, so this error is thrown.

Source

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

		sourceFolderPath !== null &&
		destinationParentFolderName !== null &&
		(destinationParentFolderName === sourceFolderPath ||
			destinationParentFolderName.startsWith(`${sourceFolderPath}/`))
	) {
		throw new Error('A folder cannot be moved inside itself');
	}

	if (transformation.source.type === 'folder') {
		const sourceFolderName = transformation.source.folderName;
		if (
			folders.some(
				(folder) =>
					folder.node !== sourceItem.node &&
					folder.name === sourceFolderName &&
					folder.parentFolderName === destinationParentFolderName,
			)
		) {
			throw new Error(
				`A folder named "${sourceFolderName}" already exists in the destination`,
			);
		}
	}

	const sourceReturnStatement = getEnclosingReturnStatement(sourceItem.path);
	deleteJsxElementAtPath(sourceItem.path);
	const element = stripParenthesizedExtra(sourceItem.node);
	if (transformation.destination.type === 'root') {
		appendElementToRoot({element, returnStatement: sourceReturnStatement});
	} else if (transformation.destination.type === 'folder') {
		appendElementToFolder({
			element,
			folderElement: (destinationFolder as unknown as LocatedItem).node,
		});
	} else {
		const targetItem = target as unknown as LocatedItem;
		const targetIndex = targetItem.parent.children.indexOf(targetItem.node);

View on GitHub (pinned to a6a7485a9a)

Solutions

  1. Rename the source folder before moving, or rename the conflicting folder in the destination
  2. Pick a different destination folder
  3. Check the destination for a folder with the same name and merge contents instead of moving

Example fix

// before
move({source: {type: 'folder', folderName: 'Assets', ...}, destination: {type: 'folder', parentName: 'Media', folderName: null}});
// after
// rename source first
move({source: {type: 'folder', folderName: 'Assets2', ...}, destination: {type: 'folder', parentName: 'Media', folderName: null}});
Defensive patterns

Strategy: validation

Validate before calling

const siblingNames = foldersIn(destinationParentFolderName).map((f) => f.name);
if (siblingNames.includes(sourceFolderName)) alert(`A folder named "${sourceFolderName}" already exists there`);

Type guard

const nameTaken = (existing: {name: string; parent: string | null}[], name: string, parent: string | null) => existing.some((f) => f.name === name && f.parent === parent);

Try / catch

try {
  await applyCodemod({transformation});
} catch (e) {
  if (String(e).includes('already exists in the destination')) {
    // prompt the user to rename or merge
  } else throw e;
}

Prevention

When it happens

Trigger: Calling applyCodemod to move a folder whose name already exists among folders sharing the computed destinationParentFolderName — e.g. moving folder 'Assets' into a parent that already contains an 'Assets' folder.

Common situations: Studio drag-drop onto a destination that visually contains a same-named folder; scripted moves without name-collision checks; duplicate names created by prior manual edits.

Related errors


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