remotion-dev/remotion · error
A folder cannot be moved inside itself
Error message
A folder cannot be moved inside itself
What it means
When moving a folder, the codemod guards against placing a folder into its own subtree, which would create an invalid/cyclic structure. If the computed destination parent path equals the source folder path or is nested under it (destinationParentFolderName starts with 'sourceFolderPath/'), this error is thrown instead of corrupting the AST.
Source
Thrown at packages/studio-codemods/src/recast-mods.ts:695
: null;
const destinationParentFolderName =
transformation.destination.type === 'root'
? null
: transformation.destination.type === 'folder'
? [
transformation.destination.parentName,
transformation.destination.folderName,
]
.filter(Boolean)
.join('/')
: (target as unknown as LocatedItem).parentFolderName;
if (
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`,
);
}
}
View on GitHub (pinned to a6a7485a9a)
Solutions
- Verify the destination path is not the source folder or nested inside it before calling applyCodemod
- Treat a drop of a folder onto its own subtree as a no-op in the caller
- Adjust the destination to a sibling location outside the source subtree
Example fix
// before
move({source: {type: 'folder', parentName: null, folderName: 'A'}, destination: {type: 'folder', parentName: 'A', folderName: 'Sub'}});
// after
move({source: {type: 'folder', parentName: null, folderName: 'A'}, destination: {type: 'folder', parentName: null, folderName: 'B'}}); // outside A Defensive patterns
Strategy: validation
Validate before calling
const srcPath = [src.parentName, src.folderName].filter(Boolean).join('/');
const dstPath = [dest.parentName, dest.folderName].filter(Boolean).join('/');
if (srcPath && dstPath && (dstPath === srcPath || dstPath.startsWith(srcPath + '/'))) return; // no-op, guard before calling Type guard
const movesIntoItself = (srcPath: string | null, dstPath: string | null) => srcPath !== null && dstPath !== null && (dstPath === srcPath || dstPath.startsWith(`${srcPath}/`)); Try / catch
try {
await applyCodemod({transformation});
} catch (e) {
if (String(e) === 'Error: A folder cannot be moved inside itself') return {changesMade: []}; // treat as intentional no-op
throw e;
} Prevention
- Always compare source folder path against destination parent path before moving
- In drag-drop UIs, disallow dropping a folder onto itself or its descendants
- Compute destination paths with the same join(parentName, folderName) logic the codemod uses
When it happens
Trigger: Calling applyCodemod with source {type: 'folder', parentName, folderName} and a destination ('folder' or a before/after target whose parent resolves to that same folder path or any descendant of it), e.g. moving folder 'A' into 'A/Sub' or reordering relative to an item inside 'A'.
Common situations: Dragging a folder onto one of its own children or itself in the studio; scripted transformations computing destination paths programmatically without cycle checks.
Related errors
- You must pass a name to a <Folder />.
- The "name" you pass into <Folder /> must be a string. Got: $
- Folder name can only contain a-z, A-Z, 0-9 and -. You passed
- Could not find folder "${folderPath}"
- A folder named "${sourceFolderName}" already exists in the d
AI-assisted analysis of remotion-dev/remotion@a6a7485a9a (2026-09-02).
Data as JSON: /api/errors/beeb5b48704aacad.
Report an issue: GitHub.