{"record":{"id":"99b876d08f4cae8d","repo":"remotion-dev/remotion","slug":"could-not-locate-the-video-opening-element","errorCode":null,"errorMessage":"Could not locate the video opening element","messagePattern":"Could not locate the video opening element","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/studio-codemods/src/split-video-from-audio.ts","lineNumber":196,"sourceCode":"}): SourceEdit => {\n\tconst existingMuted = element.openingElement.attributes.find(\n\t\t(attribute) => getAttributeName(attribute) === 'muted',\n\t);\n\tif (existingMuted) {\n\t\tif (!existingMuted.loc) {\n\t\t\tthrow new Error('Could not locate the muted attribute');\n\t\t}\n\n\t\treturn {\n\t\t\tstart: recastLocToOffset(input, existingMuted.loc.start),\n\t\t\tend: recastLocToOffset(input, existingMuted.loc.end),\n\t\t\treplacement: 'muted',\n\t\t};\n\t}\n\n\tconst {openingElement} = element;\n\tif (!openingElement.loc) {\n\t\tthrow new Error('Could not locate the video opening element');\n\t}\n\n\tconst openingStart = recastLocToOffset(input, openingElement.loc.start);\n\tconst openingEnd = recastLocToOffset(input, openingElement.loc.end);\n\tconst closingStart = openingEnd - (openingElement.selfClosing ? 2 : 1);\n\tconst lineStart = input.lastIndexOf('\\n', closingStart - 1) + 1;\n\tconst beforeClosing = input.slice(lineStart, closingStart);\n\n\tif (lineStart > openingStart && /^[\\t ]*$/.test(beforeClosing)) {\n\t\tconst lastAttribute = openingElement.attributes.at(-1);\n\t\tconst attributeIndent = lastAttribute?.loc\n\t\t\t? getLineIndent({\n\t\t\t\t\tinput,\n\t\t\t\t\toffset: recastLocToOffset(input, lastAttribute.loc.start),\n\t\t\t\t})\n\t\t\t: `${getLineIndent({input, offset: openingStart})}${getIndentationUnit(\n\t\t\t\t\tinput,\n\t\t\t\t\tprettierConfigOverride,","sourceCodeStart":178,"sourceCodeEnd":214,"githubUrl":"https://github.com/remotion-dev/remotion/blob/46a3a6bf13ca367376ff18bbb06dae2e87e0d068/packages/studio-codemods/src/split-video-from-audio.ts#L178-L214","documentation":"getMutedSourceEdit, when no existing 'muted' attribute is found, needs the <Video> element's openingElement span to append a new muted attribute. It throws when the openingElement AST node has no source location, since the insertion offset cannot be computed.","triggerScenarios":"Calling the codemod with a JSXElement whose openingElement.loc is null — the element was synthesized in memory, cloned without loc, or the source was parsed without location recording.","commonSituations":"Generated Video elements passed into the split transform; chained codemods where an earlier step rebuilt the element node; custom tooling constructing AST nodes by hand.","solutions":["Ensure the target element comes from the recast parse of real source code, not from hand-built AST nodes.","If the element was transformed earlier, re-parse the printed source and re-locate the Video element before running this codemod.","Preserve loc on cloned elements (copy openingElement.loc).","Catch the error in your pipeline and skip the file with a warning rather than aborting the whole batch."],"exampleFix":"// before: synthesized element without loc\nconst el = j.jsxElement(j.jsxOpeningElement(j.jsxIdentifier('Video'), []), ...);\ngetMutedSourceEdit({element: el, input});\n// after: use the parsed element\nconst el = findVideoElement(parse(input));\ngetMutedSourceEdit({element: el, input});","handlingStrategy":"type-guard","validationCode":"if (!element.openingElement.loc) {\n  throw new Error('Video opening element lacks loc; use a parsed node');\n}","typeGuard":"const hasOpeningLoc = (el: t.JSXElement) => el.openingElement.loc != null;","tryCatchPattern":"try {\n  const edit = getMutedSourceEdit({element, input, getAttributeName});\n} catch (err) {\n  // locate the Video element in a fresh parse and retry\n}","preventionTips":["Only pass Video elements obtained from the recast-parsed source","Preserve loc when cloning or rebuilding elements in earlier transforms","Re-parse printed output between codemod steps","Assert openingElement.loc at the codemod entry point"],"tags":["codemod","jsx","missing-loc","video"],"backgroundTag":"resource-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"}