{"record":{"id":"923e03b253f301bd","repo":"remotion-dev/remotion","slug":"a-folder-named-sourcefoldername-already-exist","errorCode":null,"errorMessage":"A folder named \"${sourceFolderName}\" already exists in the destination","messagePattern":"A folder named \"(.+?)\" already exists in the destination","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/studio-codemods/src/recast-mods.ts","lineNumber":708,"sourceCode":"\t\tsourceFolderPath !== null &&\n\t\tdestinationParentFolderName !== null &&\n\t\t(destinationParentFolderName === sourceFolderPath ||\n\t\t\tdestinationParentFolderName.startsWith(`${sourceFolderPath}/`))\n\t) {\n\t\tthrow new Error('A folder cannot be moved inside itself');\n\t}\n\n\tif (transformation.source.type === 'folder') {\n\t\tconst sourceFolderName = transformation.source.folderName;\n\t\tif (\n\t\t\tfolders.some(\n\t\t\t\t(folder) =>\n\t\t\t\t\tfolder.node !== sourceItem.node &&\n\t\t\t\t\tfolder.name === sourceFolderName &&\n\t\t\t\t\tfolder.parentFolderName === destinationParentFolderName,\n\t\t\t)\n\t\t) {\n\t\t\tthrow new Error(\n\t\t\t\t`A folder named \"${sourceFolderName}\" already exists in the destination`,\n\t\t\t);\n\t\t}\n\t}\n\n\tconst sourceReturnStatement = getEnclosingReturnStatement(sourceItem.path);\n\tdeleteJsxElementAtPath(sourceItem.path);\n\tconst element = stripParenthesizedExtra(sourceItem.node);\n\tif (transformation.destination.type === 'root') {\n\t\tappendElementToRoot({element, returnStatement: sourceReturnStatement});\n\t} else if (transformation.destination.type === 'folder') {\n\t\tappendElementToFolder({\n\t\t\telement,\n\t\t\tfolderElement: (destinationFolder as unknown as LocatedItem).node,\n\t\t});\n\t} else {\n\t\tconst targetItem = target as unknown as LocatedItem;\n\t\tconst targetIndex = targetItem.parent.children.indexOf(targetItem.node);","sourceCodeStart":690,"sourceCodeEnd":726,"githubUrl":"https://github.com/remotion-dev/remotion/blob/a6a7485a9aeb04219510fbe4874f8941486424df/packages/studio-codemods/src/recast-mods.ts#L690-L726","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Rename the source folder before moving, or rename the conflicting folder in the destination","Pick a different destination folder","Check the destination for a folder with the same name and merge contents instead of moving"],"exampleFix":"// before\nmove({source: {type: 'folder', folderName: 'Assets', ...}, destination: {type: 'folder', parentName: 'Media', folderName: null}});\n// after\n// rename source first\nmove({source: {type: 'folder', folderName: 'Assets2', ...}, destination: {type: 'folder', parentName: 'Media', folderName: null}});","handlingStrategy":"validation","validationCode":"const siblingNames = foldersIn(destinationParentFolderName).map((f) => f.name);\nif (siblingNames.includes(sourceFolderName)) alert(`A folder named \"${sourceFolderName}\" already exists there`);","typeGuard":"const nameTaken = (existing: {name: string; parent: string | null}[], name: string, parent: string | null) => existing.some((f) => f.name === name && f.parent === parent);","tryCatchPattern":"try {\n  await applyCodemod({transformation});\n} catch (e) {\n  if (String(e).includes('already exists in the destination')) {\n    // prompt the user to rename or merge\n  } else throw e;\n}","preventionTips":["Check sibling folder names at the destination before initiating the move","Enforce unique folder names per parent when creating folders","Offer rename/merge flows instead of raw moves when collisions are detected"],"tags":["codemod","validation","naming-collision"],"backgroundTag":"naming-collision","analyzedSha":"a6a7485a9aeb04219510fbe4874f8941486424df","analyzedAt":"2026-09-02T16:25:19.997Z","contentChangedAt":"2026-09-02T16:25:19.997Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}