{"record":{"id":"7f8d02fe728a8d44","repo":"withastro/astro","slug":"noimagemetadata","errorCode":"NoImageMetadata","errorMessage":"Could not process image metadata for `${transform.src}`.","messagePattern":"Could not process image metadata for `(.+?)`\\.","errorType":"exception","errorClass":"AstroError","httpStatus":null,"severity":"error","filePath":"packages/astro/src/assets/services/sharp.ts","lineNumber":171,"sourceCode":"\n\t\tconst bufferFormat = detector(inputBuffer);\n\t\t// Resolve the output format from the buffer when validateOptions deferred (ambiguous remote URL hit SSR, manually formed URLs etc)\n\t\tconst outputFormat = transform.format ?? resolveDefaultOutputFormat(bufferFormat);\n\n\t\t// TODO: Sharp has some support for SVGs, we could probably support this once Sharp is the default and only service.\n\t\tif (outputFormat === 'svg') {\n\t\t\tif (bufferFormat && bufferFormat !== 'svg') {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`⚠️  Astro expected an SVG for \"${transform.src}\" but the source is ${bufferFormat}. Passing it through as ${bufferFormat} instead.`,\n\t\t\t\t);\n\t\t\t\treturn { data: inputBuffer, format: bufferFormat as ImageOutputFormat };\n\t\t\t}\n\t\t\treturn { data: inputBuffer, format: 'svg' };\n\t\t}\n\n\t\t// If we couldn't figure out the format, it's probably something weird we shouldn't try to process.\n\t\tif (!bufferFormat) {\n\t\t\tthrow new AstroError({\n\t\t\t\t...AstroErrorData.NoImageMetadata,\n\t\t\t\tmessage: AstroErrorData.NoImageMetadata.message(transform.src),\n\t\t\t});\n\t\t}\n\n\t\tif (bufferFormat === 'svg' && !config.dangerouslyProcessSVG) {\n\t\t\tthrow new AstroError({\n\t\t\t\t...AstroErrorData.UnsupportedImageFormat,\n\t\t\t\tmessage: `SVG image processing is disabled, but the source for \"${transform.src}\" is an SVG. Pass it through unchanged by setting \\`format=\"svg\"\\` on the component, or set \\`image.dangerouslyProcessSVG: true\\` to rasterize SVG sources.`,\n\t\t\t});\n\t\t}\n\n\t\tconst result = sharp(inputBuffer, {\n\t\t\tfailOn: 'none',\n\t\t\tpages: -1,\n\t\t\tlimitInputPixels: config.service.config.limitInputPixels,\n\t\t});\n","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/withastro/astro/blob/d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca/packages/astro/src/assets/services/sharp.ts#L153-L189","documentation":"Thrown by the sharp service when it cannot determine the input image's format from the buffer (bufferFormat is falsy). Sharp uses a sniff to detect format; if no format is detected the source is treated as unprocessable and NoImageMetadata is thrown with transform.src in the message. This is separate from the SVG path which is handled first.","triggerScenarios":"Passing a transform to sharp whose inputBuffer has no detectable format — e.g. a corrupt/truncated file, a non-image binary, an empty buffer, or a format sharp's sniffer does not recognize. Only reached when outputFormat is not 'svg' and bufferFormat is falsy.","commonSituations":"A downloaded/cached image that is truncated, a file that is not actually an image (e.g. an HTML error page saved as .png), a zero-byte file, or an unsupported exotic format passed to sharp.","solutions":["Verify the source file is a complete, valid image of a supported format.","Re-download/replace the corrupt or truncated source.","Confirm the URL actually serves image bytes (not an error page) — check content-type.","If the source is SVG, set format: 'svg' to take the SVG pass-through path.","Open the file in an image viewer to confirm it is not corrupt."],"exampleFix":"// before - remote URL returns an HTML 404 page saved as .png\ngetImage({ src: 'https://cdn/missing.png', width: 100, height: 100 })\n\n// after - point at a real, valid image\ngetImage({ src: 'https://cdn/real.png', width: 100, height: 100 })","handlingStrategy":"validation","validationCode":"import { fileTypeFromBuffer } from 'file-type';\nasync function hasDetectableFormat(buf: Buffer): Promise<boolean> {\n  try { return !!(await fileTypeFromBuffer(buf)); } catch { return false; }\n}","typeGuard":null,"tryCatchPattern":"try { await service.transform(inputBuffer, transform); }\ncatch (e) {\n  if (e instanceof AstroError && e.code === 'NoImageMetadata') {\n    // source is corrupt/non-image; replace it before retrying\n  }\n}","preventionTips":["Validate source files are complete, real images before processing.","Confirm remote URLs serve image bytes (check content-type), not error pages.","Use format='svg' for SVG sources to take the SVG pass-through path."],"tags":["images","sharp","metadata","corrupt-file"],"backgroundTag":null,"analyzedSha":"d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca","analyzedAt":"2026-08-12T13:37:29.035Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}