remotion-dev/remotion · error

Could not locate the new folder

Error message

Could not locate the new folder

What it means

Thrown at the end of getNewFolderSourceEdits (folder-source-edits.ts:216) when the recast traversal found the codemod's newly grafted `<Folder>` node nowhere: `insertionEdit` stayed null. It means the AST transformation reported a change but no JSX element containing the un-located inserted Folder child could be found to generate a text edit from.

Solutions

  1. Reload Studio / re-read the Root file and retry creating the folder
  2. Verify the file does not already contain the folder (duplicate insertion aborts the edit)
  3. Add the <Folder name="..."> wrapper manually around the target compositions
Defensive patterns

Strategy: try-catch

Validate before calling

if (getLocatedItemsFromSource(input).some(isFolderNamed(codeMod))) {
  return; // folder already present; nothing to create
}

Try / catch

try {
  editFolderInSource({codeMod, input});
} catch (e) {
  if (e instanceof Error && e.message === 'Could not locate the new folder') {
    // retry once after reloading the file, else instruct manual edit
  }
}

Prevention

When it happens

Trigger: Calling editFolderInSource with a `new-folder` RecastCodemod where applyCodemod mutated the AST but the visited JSX nodes' children do not contain a location-less JSXElement with a resolvable folder `name` — e.g. the Folder was inserted into a non-traversable node type or the grafted node does not match the finder's shape.

Common situations: A stale Studio state where the folder was already created, or Root files where the parent element under which the folder is added is expressed in a way recast's visit cannot re-enter (spreads, conditional expressions).

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


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

Appendix: source

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

			insertionEdit = getInsertionRootSourceEdit({
				input,
				insertion: printInsertedJsx({
					element: inserted as never,
					input,
					prettierConfigOverride: null,
				}),
				root: root as never,
				nullRoot: null,
				prettierConfigOverride: null,
				insertInside: Boolean(jsxNode.loc),
			});
			return false;
		},
	});

	if (insertionEdit === null) {
		throw new Error('Could not locate the new folder');
	}

	return [
		insertionEdit,
		...getInsertImportSourceEdits({
			ast,
			input,
			snapshots,
			prettierConfigOverride: null,
		}),
	];
};

const getFolderNameAttribute = (folder: JSXElement) => {
	const attribute = folder.openingElement.attributes.find(
		(candidate) =>
			candidate.type === 'JSXAttribute' &&
			candidate.name.type === 'JSXIdentifier' &&

View on GitHub (pinned to 46a3a6bf13)