remotion-dev/remotion · error

Could not locate the

Error message

Could not locate the "${update.name}" attribute

What it means

When updating composition metadata, the codemod replaces the value of an existing attribute (fps, durationInFrames, width, height). If the attribute's value node has no loc AND the attribute node itself has no loc, no source range can be targeted for the replacement, so it throws with the attribute name.

Solutions

  1. Re-parse the original source and retry the codemod on a fresh AST
  2. Reformat the file with prettier so attributes exist as plain source text, then re-run
  3. Edit the attribute value manually

Example fix

// before: <Composition {.../* width built programmatically, no loc */}
// after: re-run codemod on file containing literal: <Composition ... width={1080} />
Defensive patterns

Strategy: try-catch

Validate before calling

const attributesLocated = (ast: any) => JSON.stringify(ast).match(/"loc":null/) === null;

Type guard

const hasLoc = (n: {loc?: unknown} | null | undefined) => !!n && n.loc != null;

Try / catch

try {
  editCompositionInSource({input, codeMod});
} catch (e) {
  if ((e as Error).message.includes('Could not locate the')) {
    // reparse original source or edit the attribute manually
  }
}

Prevention

When it happens

Trigger: Visiting the matching <Composition> where a metadata JSXAttribute (e.g. width) exists but both metadataAttribute.value.loc and metadataAttribute.loc are undefined — typically an attribute node synthesized by a previous AST transformation.

Common situations: Files previously rewritten by codemods that built attributes programmatically without preserving recast locations.

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/b5e71eff86f275a3. Report an issue: GitHub.

Appendix: source

Thrown at packages/studio-codemods/src/composition-source-edits.ts:205

								start: recastLocToOffset(
									input,
									metadataAttribute.value.loc.start,
								),
								end: recastLocToOffset(input, metadataAttribute.value.loc.end),
								replacement: `{${update.value}}`,
							});
						} else if (metadataAttribute.loc) {
							const offset = recastLocToOffset(
								input,
								metadataAttribute.loc.end,
							);
							edits.push({
								start: offset,
								end: offset,
								replacement: `={${update.value}}`,
							});
						} else {
							throw new Error(
								`Could not locate the "${update.name}" attribute`,
							);
						}

						changesMade.push({
							description: `Replaced ${update.description}`,
						});
					}

					const missingMetadata = metadata.filter(
						(item) => item.value !== null && !existingMetadata.has(item.name),
					);
					if (missingMetadata.length > 0) {
						const {openingElement} = element;
						if (!openingElement.loc || !openingElement.name.loc) {
							throw new Error(
								'Could not locate the composition opening element',
							);

View on GitHub (pinned to 46a3a6bf13)