{"record":{"id":"aa48f4939472e391","repo":"remotion-dev/remotion","slug":"could-not-locate-the-composition-insertion-target","errorCode":null,"errorMessage":"Could not locate the composition insertion target","messagePattern":"Could not locate the composition insertion target","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/studio-codemods/src/composition-source-edits.ts","lineNumber":105,"sourceCode":"\t\t\t\t\t);\n\t\t\t\t\tif (attribute?.type === 'JSXAttribute') {\n\t\t\t\t\t\tattribute.value = recast.types.builders.jsxExpressionContainer(\n\t\t\t\t\t\t\trecast.types.builders.identifier(component),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// A newly generated fragment wraps the existing lone root.\n\t\t\t\tconst root = node.loc\n\t\t\t\t\t? node\n\t\t\t\t\t: node.children?.find(\n\t\t\t\t\t\t\t(child) => child.type === 'JSXElement' && child.loc,\n\t\t\t\t\t\t);\n\t\t\t\tif (\n\t\t\t\t\t!root ||\n\t\t\t\t\t(root.type !== 'JSXElement' && root.type !== 'JSXFragment')\n\t\t\t\t) {\n\t\t\t\t\tthrow new Error('Could not locate the composition insertion target');\n\t\t\t\t}\n\n\t\t\t\tedits.push(\n\t\t\t\t\tgetInsertionRootSourceEdit({\n\t\t\t\t\t\tinput,\n\t\t\t\t\t\tinsertion: printInsertedJsx({\n\t\t\t\t\t\t\telement: inserted,\n\t\t\t\t\t\t\tinput,\n\t\t\t\t\t\t\tprettierConfigOverride: null,\n\t\t\t\t\t\t}),\n\t\t\t\t\t\troot,\n\t\t\t\t\t\tnullRoot: null,\n\t\t\t\t\t\tprettierConfigOverride: null,\n\t\t\t\t\t\tinsertInside: Boolean(node.loc),\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t\treturn false;\n\t\t\t},","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/remotion-dev/remotion/blob/46a3a6bf13ca367376ff18bbb06dae2e87e0d068/packages/studio-codemods/src/composition-source-edits.ts#L87-L123","documentation":"For a new-composition codemod, editCompositionInSource finds a freshly generated (location-less) JSX element and then determines the insertion root: either the surrounding element (if it has real source locations) or its first located JSXElement/JSXFragment child. If neither exists, there is no anchor in the original source to insert the new composition, so it throws.","triggerScenarios":"The visitNode pass finds a generated JSX element but its container node has no loc and none of the container's children with type JSXElement have loc either (no root with source locations).","commonSituations":"The target root file is not normal JSX (e.g. the composition list is built programmatically or the file was already heavily machine-generated), leaving no parseable anchor element.","solutions":["Ensure the root returns/renders a static JSX element or fragment with real source text","Reformat/rewrite the file so the composition root is literal JSX, then re-run","Insert the new <Composition> manually"],"exampleFix":"// before: export const RemotionRoot = () => getCompositions().map(c => render(c))\n// after:\nexport const RemotionRoot = () => (\n  <>\n    <Composition id=\"MyComp\" component={MyComp} ...\n  </>\n);","handlingStrategy":"validation","validationCode":"const rootIsStaticJsx = /(<\\s*[A-Za-z<>/>]|<>\\s)/.test(rootFileSource);\nif (!/<[A-Z][\\w.]*[\\s/>]/.test(rootFileSource)) throw new Error('Root file must render a literal JSX element');","typeGuard":"const isLocatedRoot = (n: any): boolean => n && (n.type === 'JSXElement' || n.type === 'JSXFragment') && n.loc != null;","tryCatchPattern":"try {\n  editCompositionInSource({input, codeMod});\n} catch (e) {\n  if ((e as Error).message.includes('Could not locate the composition insertion target')) {\n    // rewrite Root to return literal JSX, then retry\n  }\n}","preventionTips":["Keep RemotionRoot returning literal <Composition> elements","Avoid building the composition list programmatically","Format the Root file with prettier before running add-composition codemods"],"tags":["codemod","jsx","insertion"],"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"}