{"record":{"id":"ba8cbff90fa8ed59","repo":"withastro/astro","slug":"expectedimage","errorCode":"ExpectedImage","errorMessage":"Expected `src` property for `getImage` or `<Image />` to be either an ESM imported image or a string with the path of a remote image. Received `${src}` (type: `${typeofOptions}`).\n\nFull serialized options received: `${fullOptions}`.","messagePattern":"Expected `src` property for `getImage` or `<Image />` to be either an ESM imported image or a string with the path of a remote image\\. Received `(.+?)` \\(type: `(.+?)`\\)\\.\n\nFull serialized options received: `(.+?)`\\.","errorType":"exception","errorClass":"AstroError","httpStatus":null,"severity":"error","filePath":"packages/astro/src/assets/internal.ts","lineNumber":61,"sourceCode":"\t\treturn service;\n\t}\n\n\treturn globalThis.astroAsset.imageService;\n}\n\nexport async function getImage(\n\toptions: UnresolvedImageTransform,\n\timageConfig: AstroConfig['image'] & AstroAdapterClientConfig,\n\tlogger: AstroRuntimeLogger,\n): Promise<GetImageResult> {\n\tif (!options || typeof options !== 'object') {\n\t\tthrow new AstroError({\n\t\t\t...AstroErrorData.ExpectedImageOptions,\n\t\t\tmessage: AstroErrorData.ExpectedImageOptions.message(JSON.stringify(options)),\n\t\t});\n\t}\n\tif (typeof options.src === 'undefined') {\n\t\tthrow new AstroError({\n\t\t\t...AstroErrorData.ExpectedImage,\n\t\t\tmessage: AstroErrorData.ExpectedImage.message(\n\t\t\t\toptions.src,\n\t\t\t\t'undefined',\n\t\t\t\tJSON.stringify(options),\n\t\t\t),\n\t\t});\n\t}\n\n\tif (isImageMetadata(options)) {\n\t\tthrow new AstroError(AstroErrorData.ExpectedNotESMImage);\n\t}\n\n\tconst service = await getConfiguredImageService();\n\n\t// If the user inlined an import, something fairly common especially in MDX, or passed a function that returns an Image, await it for them\n\tconst resolvedOptions: ImageTransform = {\n\t\t...options,","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/withastro/astro/blob/e294953aa8aadd98d5be92e60a03037b05dbdfd4/packages/astro/src/assets/internal.ts#L43-L79","documentation":"`getImage()` validates that `options.src` is defined before doing anything else (packages/astro/src/assets/internal.ts:59). An options object present but with `src` undefined (missing key, explicitly `undefined`, or a destructuring miss) throws `ExpectedImage` with the serialized options included.","triggerScenarios":"`getImage({})`, `getImage({ width: 800 })`, or `src` computed from a lookup that returned undefined (e.g. a map keyed by slug where the slug is wrong).","commonSituations":"Looping over CMS/JSON data where some entries lack an image field; optional chaining that silently yields undefined; renamed props during refactors.","solutions":["Ensure the options object contains a `src` that is either an ESM-imported image or a remote URL string.","Validate data before rendering: skip or substitute a placeholder when a record has no image.","Type the options parameter (`UnresolvedImageTransform`) so TypeScript flags missing `src` at compile time."],"exampleFix":"// before — entry.image is undefined for some records\ngetImage({ src: entry.image, width: 800 });\n\n// after — guard the data\nif (!entry.image) return null;\ngetImage({ src: entry.image, width: 800 });","handlingStrategy":"type-guard","validationCode":"if (!('src' in options) || options.src === undefined) {\n  throw new Error(`getImage options missing src: ${JSON.stringify(options)}`);\n}","typeGuard":"function hasDefinedSrc(value: unknown): value is { src: string | ImageMetadata } {\n  return (\n    typeof value === 'object' &&\n    value !== null &&\n    'src' in value &&\n    (value as { src?: unknown }).src !== undefined\n  );\n}","tryCatchPattern":null,"preventionTips":["Validate CMS records for image fields before mapping them to components.","Type props as { src: ImageMetadata | string } to get compile-time enforcement."],"tags":["images","getimage","api-usage","data-validation"],"backgroundTag":"missing-required-argument","analyzedSha":"e294953aa8aadd98d5be92e60a03037b05dbdfd4","analyzedAt":"2026-08-18T18:48:03.901Z","contentChangedAt":"2026-08-18T18:48:03.901Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}