withastro/astro · error

Astro could not optimize image "${transform.src}". Sharp doe

Error message

Astro could not optimize image "${transform.src}". Sharp doesn't support this format. The image will be used unoptimized. Consider converting to WebP or placing in the public/ folder.

What it means

Error "Astro could not optimize image "${transform.src}". Sharp doesn't support this format. The image will be used unoptimized. Consider converting to WebP or placing in the public/ folder." thrown in withastro/astro.

Source

Thrown at packages/astro/src/assets/services/sharp.ts:253

		} else if (outputFormat === 'png') {
			result.png(encoderOptions as PngOptions | undefined);
		} else if (outputFormat === 'avif') {
			result.avif(encoderOptions as AvifOptions | undefined);
		} else if (outputFormat === 'jpeg' || outputFormat === 'jpg') {
			result.jpeg(encoderOptions as JpegOptions | undefined);
		} else {
			result.toFormat(outputFormat as keyof FormatEnum, encoderOptions);
		}

		let data: Uint8Array;
		let info: { format: string };
		try {
			({ data, info } = await result.toBuffer({ resolveWithObject: true }));
		} catch {
			// Sharp cannot decode this image (e.g. animated AVIF sequences).
			// Pass it through unmodified rather than crashing the build. When Sharp adds support for these
			// formats, the image will be optimized automatically without code changes.
			logger.warn(
				`Astro could not optimize image "${transform.src}". Sharp doesn't support this format. The image will be used unoptimized. Consider converting to WebP or placing in the public/ folder.`,
			);
			return { data: inputBuffer, format: bufferFormat as ImageOutputFormat };
		}

		// Sharp can sometimes return a SharedArrayBuffer when using WebAssembly.
		// SharedArrayBuffers need to be copied into an ArrayBuffer in order to be manipulated.
		const needsCopy = 'buffer' in data && data.buffer instanceof SharedArrayBuffer;

		return {
			data: needsCopy ? new Uint8Array(data) : data,
			format: info.format as ImageOutputFormat,
		};
	},
};

export default sharpService;

View on GitHub (pinned to e294953aa8)

When it happens

Trigger: Thrown at packages/astro/src/assets/services/sharp.ts:253 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/e0e60cb5bb32ec4f. Report an issue: GitHub.