remotion-dev/remotion · error
Could not locate the folder to delete
Error message
Could not locate the folder to delete
What it means
Thrown by getDeleteFolderSourceEdit (folder-source-edits.ts:281) when the located folder's JSXElement has no source location (`node.loc` is null). Deleting a folder requires computing character offsets from the node's loc; a location-less node (typically one synthesized by an earlier AST mutation in the same codemod run) cannot be mapped back to text.
Solutions
- Reload the Studio / re-parse the file so all JSX nodes regain source locations, then delete again
- Delete the <Folder> element manually in the editor
- Avoid chaining create+delete folder operations on the same unsaved file
Defensive patterns
Strategy: try-catch
Validate before calling
// Re-parse the file first so nodes carry fresh locations
const ast = parseAst(input);
if (getLocatedItems(ast).every((i) => !i.node.loc)) {
throw new Error('File nodes lack source locations; save/reformat first');
} Type guard
const isLocatable = (node: JSXElement): node is JSXElement & {loc: NonNullable<JSXElement['loc']>} => node.loc !== null && node.loc !== undefined; Try / catch
try {
editFolderInSource({codeMod, input});
} catch (e) {
if (e instanceof Error && e.message === 'Could not locate the folder to delete') {
// delete the <Folder> block manually
}
} Prevention
- Reload/re-parse the file before chained create+delete operations
- Avoid deleting folders whose JSX was just synthesized in the same run
- Keep Root files hand-written so recast locations stay intact
When it happens
Trigger: A `delete-folder` codemod targets a folder whose JSXElement node lost its recast `loc`, usually because the node was created or replaced programmatically during applyCodemod rather than existing in the original parsed source.
Common situations: Deleting a folder right after another codemod moved/created nodes in the same file within one Studio session, or Root files where the folder JSX was generated rather than hand-written.
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
- Cannot duplicate JSX element with no parent
- Cannot split a JSX sequence without a source location
- Cannot split JSX sequence with no parent
- Could not find a root JSX element
- Could not find a root JSX element
AI-assisted analysis of remotion-dev/remotion@46a3a6bf13 (2026-09-18).
Data as JSON: /api/errors/473a9d6bf8d89bd5.
Report an issue: GitHub.
Appendix: source
Thrown at packages/studio-codemods/src/folder-source-edits.ts:281
return lines
.map((line) => (line.trim() === '' ? '' : line.slice(commonIndent.length)))
.join(getEndOfLine(source));
};
const isMeaningfulChild = (child: JSXElement['children'][number]) =>
child.type !== 'JSXText' || child.value.trim() !== '';
const getDeleteFolderSourceEdit = ({
input,
located,
}: {
input: string;
located: LocatedItem;
}): SourceEdit => {
const {node, path} = located;
if (!node.loc) {
throw new Error('Could not locate the folder to delete');
}
const openingEnd = node.openingElement.loc
? recastLocToOffset(input, node.openingElement.loc.end)
: null;
const closingStart = node.closingElement?.loc
? recastLocToOffset(input, node.closingElement.loc.start)
: null;
const inner =
openingEnd === null || closingStart === null
? ''
: normalizeBlock(input.slice(openingEnd, closingStart));
if (!located.directJsxChild) {
const meaningfulChildren = node.children.filter(isMeaningfulChild);
if (meaningfulChildren.length === 0) {
return {
start: recastLocToOffset(input, node.loc.start),View on GitHub (pinned to 46a3a6bf13)