{"record":{"id":"e4a27a2e3b0b446a","repo":"remotion-dev/remotion","slug":"could-not-locate-the-composition-component-root","errorCode":null,"errorMessage":"Could not locate the composition component root","messagePattern":"Could not locate the composition component root","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/studio-codemods/src/insert-jsx-element.ts","lineNumber":2288,"sourceCode":"\t\tconst nullIndent = getLineIndent({input, offset: nullStart});\n\t\treturn {\n\t\t\tend: nullEnd,\n\t\t\treplacement: [\n\t\t\t\t'(',\n\t\t\t\t`${nullIndent}${unit}<>`,\n\t\t\t\tindentInsertedJsx({\n\t\t\t\t\tindent: `${nullIndent}${unit}${unit}`,\n\t\t\t\t\tinsertion,\n\t\t\t\t}),\n\t\t\t\t`${nullIndent}${unit}</>`,\n\t\t\t\t`${nullIndent})`,\n\t\t\t].join(endOfLine),\n\t\t\tstart: nullStart,\n\t\t};\n\t}\n\n\tif (!root?.loc) {\n\t\tthrow new Error('Could not locate the composition component root');\n\t}\n\n\tif (insertInside) {\n\t\tconst closing =\n\t\t\troot.type === 'JSXFragment' ? root.closingFragment : root.closingElement;\n\t\tif (!closing?.loc) {\n\t\t\tif (root.type !== 'JSXElement' || !root.openingElement.loc) {\n\t\t\t\tthrow new Error('Could not locate the composition closing tag');\n\t\t\t}\n\n\t\t\tconst openingStart = recastLocToOffset(\n\t\t\t\tinput,\n\t\t\t\troot.openingElement.loc.start,\n\t\t\t);\n\t\t\tconst openingEnd = recastLocToOffset(input, root.openingElement.loc.end);\n\t\t\tconst openingIndent = getLineIndent({input, offset: openingStart});\n\t\t\treturn {\n\t\t\t\tstart: openingStart,","sourceCodeStart":2270,"sourceCodeEnd":2306,"githubUrl":"https://github.com/remotion-dev/remotion/blob/46a3a6bf13ca367376ff18bbb06dae2e87e0d068/packages/studio-codemods/src/insert-jsx-element.ts#L2270-L2306","documentation":"When inserting a JSX element into a composition, the codemod locates the composition component's root JSX node to compute insertion offsets. If the root node was not found or has no source location (root?.loc missing), no insertion position can be computed and this error is thrown.","triggerScenarios":"Calling the insert-JSX-element codemod against a file where the composition component root is missing — e.g. the component returns nothing renderable, the root is not a JSX element/fragment, or parsing located no root node for the given composition.","commonSituations":"Targeting a composition file that was heavily hand-edited; a component whose return statement is not JSX (returns null or a variable); pointing the codemod at the wrong file or composition ID.","solutions":["Ensure the composition component returns JSX directly and the file contains the expected root element.","Check you are targeting the correct file/composition for the insertion.","If the component returns a variable, inline the JSX so a root node with location info exists.","Re-format the file so location metadata is stable, then rerun the codemod."],"exampleFix":"// before -> root not locatable\nconst MyComp = () => renderContent();\n// after\nconst MyComp = () => {\n  return (\n    <div>{/* insert target */}</div>\n  );\n};","handlingStrategy":"validation","validationCode":"const parsed = parse(compositionSource);\nconst root = findCompositionRoot(parsed);\nif (!root || !root.loc) {\n  throw new Error('Composition component has no locatable JSX root; cannot insert element');\n}","typeGuard":null,"tryCatchPattern":"try {\n  insertJsxElementInComposition(opts);\n} catch (e) {\n  if (e instanceof Error && e.message === 'Could not locate the composition component root') {\n    console.error('Verify the file contains the target composition returning JSX');\n  } else throw e;\n}","preventionTips":["Ensure composition components return JSX directly","Confirm the codemod targets the correct file/composition ID","Avoid heavily hand-editing files before codemod runs"],"tags":["jsx","codemod","ast","lookup-failed"],"backgroundTag":"entity-not-found","analyzedSha":"46a3a6bf13ca367376ff18bbb06dae2e87e0d068","analyzedAt":"2026-09-18T00:12:20.256Z","contentChangedAt":"2026-09-18T00:12:20.256Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}