remotion-dev/remotion · error · Error

Could not locate the folder to rename

Error message

Could not locate the folder to rename

What it means

editFolderInSource in @remotion/studio-codemods edits a folder in the source of a composition. For a 'rename-folder' codemod it first resolves the folder node from the AST; if no folder node could be located (folder === null), it refuses to proceed with this error instead of guessing at edits. This is a lookup failure, not a parse failure.

Solutions

  1. Verify the folder still exists in the composition source file and that its name/id matches what the codemod input references.
  2. Re-open/refresh the studio state so folder references are re-resolved from current source.
  3. Re-parse the file and confirm the folder node is found before calling editFolderInSource (run the same lookup your pipeline uses).
  4. If the file was hand-edited, revert or fix the edit so the folder markup is intact, then retry the rename.

Example fix

// before (folder id stale)
await editFolderInSource({input: src, codeMod: {type: 'rename-folder', folderId: 'old-id', newName: 'x'}});
// after (resolve the real folder id first)
const folder = locateFolder(src, 'My Folder');
if (!folder) throw new Error('Folder missing from source');
await editFolderInSource({input: src, codeMod: {type: 'rename-folder', folderId: folder.id, newName: 'x'}});
Defensive patterns

Strategy: validation

Validate before calling

const folder = sourceFile && locateFolderNode(sourceFile, folderRef);
if (!folder) throw new Error(`Folder "${folderRef}" not found in source; refresh state before rename`);

Type guard

const isFolderLocated = (f: unknown): f is LocatedFolder =>
  Boolean(f) && typeof f === 'object' && 'node' in (f as object);

Try / catch

try {
  await editFolderInSource({input, codeMod});
} catch (e) {
  if (e instanceof Error && e.message === 'Could not locate the folder to rename') {
    console.warn('Folder missing; reloading studio state');
    await refreshSourceState();
  } else throw e;
}

Prevention

When it happens

Trigger: Calling editFolderInSource with a 'rename-folder' codeMod where the folder ID/name passed in the input does not match any folder node found in the parsed source AST, so folder resolution returns null.

Common situations: Renaming a folder in Remotion Studio after the underlying file was edited manually or reformatted so the folder node no longer matches; stale folder references in studio state pointing at a folder that was deleted or whose markup changed.

Understand the failure class

Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.

Related errors


AI-assisted analysis of remotion-dev/remotion@46a3a6bf13 (2026-09-18). Data as JSON: /api/errors/ad2fed9b852a717e. Report an issue: GitHub.

Appendix: source

Thrown at packages/studio-codemods/src/folder-source-edits.ts:497

			? getFolder({
					folderName: codeMod.folderName,
					items,
					parentName: codeMod.parentName,
				})
			: null;
	const {newAst, changesMade} = applyCodemod({file: ast, codeMod});
	if (changesMade.length === 0) {
		throw new Error(
			'Unable to calculate the changes needed for this file. Edit the file manually.',
		);
	}

	let edits: SourceEdit[];
	if (codeMod.type === 'new-folder') {
		edits = getNewFolderSourceEdits({ast: newAst, input});
	} else if (codeMod.type === 'rename-folder') {
		if (folder === null) {
			throw new Error('Could not locate the folder to rename');
		}

		edits = [
			getJsxStringAttributeValueSourceEdit({
				attribute: getFolderNameAttribute(folder.node),
				input,
				newValue: codeMod.newName,
			}),
		];
	} else if (codeMod.type === 'delete-folder') {
		if (folder === null) {
			throw new Error('Could not locate the folder to delete');
		}

		edits = [getDeleteFolderSourceEdit({input, located: folder})];
	} else {
		edits = getMoveSourceEdits({codeMod, input, items});
	}

View on GitHub (pinned to 46a3a6bf13)