withastro/astro · error · AstroError
PluginContentImportsError
PluginContentImportsError
Error message
Unexpected error processing content collection data.
What it means
A catch-all in vite-plugin-content-imports: while stringifying collection data for a generated module, something threw a value that is not an Error instance (for example a string thrown from a custom loader or a getter). Because there is no stack to preserve, Astro wraps it in PluginContentImportsError.
Solutions
- Run astro build with verbose logging to identify the entry being processed when it throws.
- Audit custom loader/transform code for throw statements raising strings or plain objects; always throw new Error(...).
- Apply the serialization fixes for UnsupportedConfigTransformError — this error shares the same root cause.
- If no custom code is involved, report an Astro issue with the data shape that triggered it.
Example fix
// before (in a custom loader)
if (!row.id) throw 'row missing id';
// after
if (!row.id) throw new Error(`row missing id in ${row}`); Defensive patterns
Strategy: try-catch
Validate before calling
// Enforce Error-typed throws in your loader code
function assertValid(value, msg) {
if (!value) throw new Error(msg); // never throw a bare string
} Try / catch
try {
await build();
} catch (e) {
if (e instanceof Error && e.name === 'PluginContentImportsError') {
// re-run with verbose logging to find the entry, then audit custom loader throws
}
throw e;
} Prevention
- Always throw new Error(...) with a message; never throw strings or plain objects.
- Keep transform output serializable (see UnsupportedConfigTransformError).
- Isolate third-party loaders when this appears to identify which one threw.
When it happens
Trigger: Custom loaders or transforms that throw non-Error values (throw 'bad data'); exotic objects whose getters throw plain strings during serialization.
Common situations: Almost always co-occurs with UnsupportedConfigTransformError; third-party loader bugs; defensive throw statements in shared code that raise strings.
Related errors
- UnsupportedConfigTransformError
- Collection loader for
- Live content collections must be defined in…
- A content collection is defined with legacy features (e.g…
- ActionsReturnedInvalidDataError
AI-assisted analysis of withastro/astro@e294953aa8 (2026-08-18).
Data as JSON: /api/errors/cd45f556ea772dd3.
Report an issue: GitHub.
Appendix: source
Thrown at packages/astro/src/content/vite-plugin-content-imports.ts:441
return `new URL(${JSON.stringify(value.href)})`;
}
// For Astro assets, add a proxy to track references
if (typeof value === 'object' && 'ASTRO_ASSET' in value) {
const { ASTRO_ASSET, ...asset } = value;
asset.fsPath = ASTRO_ASSET;
return getProxyCode(asset, isSSR);
}
});
} catch (e) {
if (e instanceof Error) {
throw new AstroError({
...AstroErrorData.UnsupportedConfigTransformError,
message: AstroErrorData.UnsupportedConfigTransformError.message(e.message),
stack: e.stack,
});
} else {
throw new AstroError({
name: 'PluginContentImportsError',
message: 'Unexpected error processing content collection data.',
});
}
}
}
View on GitHub (pinned to e294953aa8)