remotion-dev/remotion · error

Could not locate the composition id

Error message

Could not locate the composition id

What it means

For rename-composition (and other id-rewriting codemods), after matching the composition the codemod locates the id JSXAttribute to replace its string value. If no id attribute exists on the matched element, it throws this error.

Solutions

  1. Give the <Composition> an explicit static id="..." attribute
  2. Remove spread props that supply id and write it inline
  3. Rename the composition manually in the source

Example fix

// before: <Composition {...compProps} durationInFrames={100} />
// after:  <Composition id="MyComp" {...compProps} durationInFrames={100} />
Defensive patterns

Strategy: validation

Validate before calling

const hasStaticId = /<Composition[^>]*\sid="[^"]+"/.test(input);
if (!hasStaticId) throw new Error('Composition must have a static id attribute');

Type guard

const hasIdAttribute = (el: any) => el.openingElement?.attributes?.some((a: any) => a.type === 'JSXAttribute' && a.name?.name === 'id');

Try / catch

try {
  editCompositionInSource({input, codeMod});
} catch (e) {
  if ((e as Error).message.includes('Could not locate the composition id')) {
    // add an explicit id="..." attribute, then retry
  }
}

Prevention

When it happens

Trigger: editCompositionInSource with rename-composition where getCompositionId(element) matched the target id (e.g. via an expression form) but the attributes array contains no JSXAttribute named 'id' that is a JSXAttribute with a JSXIdentifier name — i.e. the id is supplied some other way (spread props like {...{id: 'x'}}, dynamic id).

Common situations: Compositions whose id comes from a spread attribute, a variable, or a shorthand construct that getCompositionId resolves differently from the attribute search.

Understand the failure class

Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.

Related errors


AI-assisted analysis of remotion-dev/remotion@46a3a6bf13 (2026-09-18). Data as JSON: /api/errors/567c423d9d4bed62. Report an issue: GitHub.

Appendix: source

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

							});
						}

						for (const item of missingMetadata) {
							changesMade.push({description: `Added ${item.description}`});
						}
					}

					return false;
				}

				const idAttribute = element.openingElement.attributes.find(
					(attr) =>
						attr.type === 'JSXAttribute' &&
						attr.name.type === 'JSXIdentifier' &&
						attr.name.name === 'id',
				);
				if (idAttribute?.type !== 'JSXAttribute') {
					throw new Error('Could not locate the composition id');
				}

				edits.push(
					getJsxStringAttributeValueSourceEdit({
						attribute: idAttribute,
						input,
						newValue: codeMod.newId,
					}),
				);
				changesMade.push({description: 'Replaced composition id'});
				return false;
			},
		});
	}

	if (changesMade.length === 0) {
		throw new Error(
			'Unable to calculate the changes needed for this file. Edit the file manually.',

View on GitHub (pinned to 46a3a6bf13)