withastro/astro · error · AstroError
ExpectedImageOptions
ExpectedImageOptions
Error message
**${context.collection}** entry is missing an ID.
Invalid data type: ${typeof data} What it means
A defensive branch at the end of Astro's function-style loader handling: after the zod union (array | record) validates successfully, the data must be an array or an object; anything else falls through to this throw. In practice it is unreachable because the schema only lets arrays and objects through. Note the throw spreads `ExpectedImageOptions` while formatting the message from ContentLoaderInvalidDataError — the error code is wrong, so if you do hit this, report it as an Astro bug.
Solutions
- Ensure your function-style loader returns a plain array or plain object (this error should never fire if error 80's validation passed).
- If you can reproduce it, file an Astro issue — both the unreachable branch and the misattributed ExpectedImageOptions code are worth reporting.
Defensive patterns
Strategy: validation
Validate before calling
function isLoaderReturnable(v: unknown): boolean {
return Array.isArray(v) || (v !== null && typeof v === 'object');
} Try / catch
try {
await getCollection('blog');
} catch (err) {
// Note: this throw carries the ExpectedImageOptions code but a ContentLoaderInvalidDataError message
if (/Invalid data type/.test((err as any).message)) {
console.error('Loader returned neither array nor object');
} else throw err;
} Prevention
- Return only plain arrays or plain objects from function-style loaders.
- If this fires with normal data, report an Astro bug — the branch is unreachable by design and the error code is misattributed.
When it happens
Trigger: Not reachable through the public API: loaderReturnSchema would already have rejected non-array/non-object data with ContentLoaderReturnsInvalidId. Only exotic cases (a custom zod setup or an Astro regression) could land here.
Common situations: Essentially none; appears only for Astro-internal bugs or patched/modified zod behavior.
Related errors
- ContentLoaderInvalidDataError
- ContentLoaderReturnsInvalidId
- A content collection is defined with legacy features (e.g…
- Collection loader for
- Your loader's schema is defined using a function. This is…
AI-assisted analysis of withastro/astro@52e6c34790 (2026-08-18).
Data as JSON: /api/errors/38aad68b85c71214.
Report an issue: GitHub.
Appendix: source
Thrown at packages/astro/src/content/content-layer.ts:534
return;
}
if (typeof data === 'object') {
for (const [id, raw] of Object.entries(data)) {
if (raw.id && raw.id !== id) {
throw new AstroError({
...AstroErrorData.ContentLoaderInvalidDataError,
message: AstroErrorData.ContentLoaderInvalidDataError.message(
context.collection,
`Object key ${JSON.stringify(id)} does not match ID ${JSON.stringify(raw.id)}`,
),
});
}
const item = await context.parseData({ id, data: raw });
context.store.set({ id, data: item });
}
return;
}
throw new AstroError({
...AstroErrorData.ExpectedImageOptions,
message: AstroErrorData.ContentLoaderInvalidDataError.message(
context.collection,
`Invalid data type: ${typeof data}`,
),
});
}
View on GitHub (pinned to 52e6c34790)