withastro/astro · error
Astro expected an SVG for "${transform.src}" but the source
Error message
Astro expected an SVG for "${transform.src}" but the source is ${bufferFormat}. Passing it through as ${bufferFormat} instead. What it means
In the Sharp image service, transform() was asked to process an image whose declared/configured format is SVG, but format detection on the actual input buffer identified it as a different format (bufferFormat). Instead of failing, Sharp passes the buffer through unoptimized in its detected format and logs this warning, so the build does not break on a mismatched extension or mislabeled src.
Source
Thrown at packages/astro/src/assets/services/sharp.ts:161
validateOptions: baseService.validateOptions,
getURL: baseService.getURL,
parseURL: baseService.parseURL,
getHTMLAttributes: baseService.getHTMLAttributes,
getSrcSet: baseService.getSrcSet,
getRemoteSize: baseService.getRemoteSize,
async transform(inputBuffer, transformOptions, config, logger) {
if (!sharp) sharp = await loadSharp();
const transform: BaseServiceTransform = transformOptions as BaseServiceTransform;
const kernel = config.service.config.kernel;
const bufferFormat = detector(inputBuffer);
// Resolve the output format from the buffer when validateOptions deferred (ambiguous remote URL hit SSR, manually formed URLs etc)
const outputFormat = transform.format ?? resolveDefaultOutputFormat(bufferFormat);
// TODO: Sharp has some support for SVGs, we could probably support this once Sharp is the default and only service.
if (outputFormat === 'svg') {
if (bufferFormat && bufferFormat !== 'svg') {
logger.warn(
`Astro expected an SVG for "${transform.src}" but the source is ${bufferFormat}. Passing it through as ${bufferFormat} instead.`,
);
return { data: inputBuffer, format: bufferFormat as ImageOutputFormat };
}
return { data: inputBuffer, format: 'svg' };
}
// If we couldn't figure out the format, it's probably something weird we shouldn't try to process.
if (!bufferFormat) {
throw new AstroError({
...AstroErrorData.NoImageMetadata,
message: AstroErrorData.NoImageMetadata.message(transform.src),
});
}
if (bufferFormat === 'svg' && !config.dangerouslyProcessSVG) {
throw new AstroError({
...AstroErrorData.UnsupportedImageFormat,View on GitHub (pinned to e294953aa8)
Solutions
- Verify the source file truly is an SVG — its extension or config entry may mislabel a JPEG/PNG as .svg
- If the file is intentionally another format, update its extension or the image's format option to match
- Rename or fix the file so the declared format matches the actual encoded format
Defensive patterns
Strategy: fallback
When it happens
Trigger: Thrown at packages/astro/src/assets/services/sharp.ts:161 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of withastro/astro@e294953aa8 (2026-09-09).
Data as JSON: /api/errors/f0331c206f303b2d.
Report an issue: GitHub.