remotion-dev/remotion · error · Error
Could not locate the import prefix to update
Error message
Could not locate the import prefix to update
What it means
getInsertImportSourceEdits adds specifiers to an existing import statement. When the statement is detected as a candidate for prefix insertion (side-effect-free import whose keyword span should be extended), the code slices the source from the statement start and matches /^import\s+/. If that regex fails to match, the assumed import prefix cannot be located and the library throws rather than corrupting the import.
Solutions
- Run this codemod on the freshly parsed, unedited source so statement.loc offsets are accurate.
- Normalize the file: remove BOM, ensure the import statement literally begins with 'import'.
- Apply all source edits through applySourceEdits in one batch instead of editing the string between computations.
- Wrap in try/catch and fall back to inserting a brand-new import statement instead of extending the existing one.
Example fix
// before
// BOM+comment confuses match
import {Video} from 'remotion';
// after: plain statement at line start
import {Video} from 'remotion'; Defensive patterns
Strategy: try-catch
Validate before calling
const prefix = input.slice(recastLocToOffset(input, statement.loc.start)).match(/^import\s+/);
if (!prefix) { throw new Error('Import statement not at expected offset'); } Type guard
const isPlainImportAtOffset = (input: string, offset: number) => /^import\s+/.test(input.slice(offset));
Try / catch
try {
edits.push(...getInsertImportSourceEdits({statement, input, addedSpecifiers}));
} catch (err) {
// append a fresh import statement instead of extending the existing one
} Prevention
- Run codemods on unmodified source so offsets align with statement.loc
- Strip BOM characters before parsing
- Avoid manual string edits between computing and applying source edits
- Ensure the import statement literally starts with the keyword 'import'
When it happens
Trigger: An import statement whose source text does not literally start with 'import ' at the computed offset — e.g. unusual whitespace/newline right after 'import' that the \s+ should catch but a preceding BOM, comment, or offset misalignment prevents; or statement.loc pointing at the wrong offset after prior edits.
Common situations: Applying edits to already-mutated source where offsets shifted; import statements preceded by comments or odd formatting; files with BOM characters; non-standard code style that confuses the prefix regex.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- Could not locate the
- Could not locate the folder insertion target
- Could not locate the import to update
- Muted attribute edit is outside the video element
- Overlapping source edit ranges
AI-assisted analysis of remotion-dev/remotion@46a3a6bf13 (2026-09-18).
Data as JSON: /api/errors/66d76a7252107d3c.
Report an issue: GitHub.
Appendix: source
Thrown at packages/studio-codemods/src/source-edits.ts:357
}
const addedSpecifiers = (statement.specifiers ?? []).filter(
(specifier) => !snapshot.specifiers.includes(specifier),
);
if (addedSpecifiers.length === 0) {
continue;
}
if (
addedSpecifiers.every(
(specifier) => specifier.type === 'ImportDefaultSpecifier',
) &&
statement.loc
) {
const importStart = recastLocToOffset(input, statement.loc.start);
const importPrefix = input.slice(importStart).match(/^import\s+/)?.[0];
if (!importPrefix) {
throw new Error('Could not locate the import prefix to update');
}
const offset = importStart + importPrefix.length;
edits.push({
end: offset,
replacement: `${addedSpecifiers.map(renderImportSpecifier).join(', ')}, `,
start: offset,
});
continue;
}
if (
addedSpecifiers.some((specifier) => specifier.type !== 'ImportSpecifier')
) {
if (!statement.loc) {
throw new Error('Could not locate the import to update');
}
View on GitHub (pinned to 46a3a6bf13)