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
- Verify the target folder element exists in the file before invoking the codemod
- Regenerate the transformation from current composition state
- 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
- Verify the folder exists in the same composition file before moving into it
- Refresh folder state after any rename or delete operation
- Provide a root fallback for move operations whose target folder may have been removed
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
- Could not find folder "${folderPath}"
- Could not find a root JSX element
- Could not find ${getCompositionOrFolderLabel(transformation.
- Could not find ${getCompositionOrFolderLabel(transformation.
- A folder cannot be moved inside itself
AI-assisted analysis of remotion-dev/remotion@a6a7485a9a (2026-09-02).
Data as JSON: /api/errors/1203f7de15d6845a.
Report an issue: GitHub.