{"record":{"id":"23825330b0dd4d29","repo":"withastro/astro","slug":"expectednotesmimage","errorCode":"ExpectedNotESMImage","errorMessage":"An ESM-imported image cannot be passed directly to `getImage()`. Instead, pass an object with the image in the `src` property.","messagePattern":"An ESM-imported image cannot be passed directly to `getImage\\(\\)`\\. Instead, pass an object with the image in the `src` property\\.","errorType":"exception","errorClass":"AstroError","httpStatus":null,"severity":"error","filePath":"packages/astro/src/assets/internal.ts","lineNumber":70,"sourceCode":"\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,\n\t\tsrc: await resolveSrc(options.src),\n\t};\n\n\tlet originalWidth: number | undefined;\n\tlet originalHeight: number | undefined;\n\n\t// Infer size for remote images if inferSize is true\n\tif (resolvedOptions.inferSize) {\n\t\tdelete resolvedOptions.inferSize; // Delete so it doesn't end up in the attributes\n\n\t\tif (isRemoteImage(resolvedOptions.src) && isRemotePath(resolvedOptions.src)) {","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/withastro/astro/blob/d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca/packages/astro/src/assets/internal.ts#L52-L88","documentation":"Thrown by getImage() when the entire options object is itself an ESM-imported image metadata object rather than a transform containing src. isImageMetadata(options) detects the non-enumerable fsPath marker that Astro injects on imports, meaning the user passed the imported image directly instead of wrapping it in { src }.","triggerScenarios":"Calling getImage(importedImage) instead of getImage({ src: importedImage }). The imported asset module's metadata object (with the hidden fsPath) is passed where a transform object is expected.","commonSituations":"Common in MDX/JSX when an author writes getImage(myImage) rather than getImage({ src: myImage }), or passes the result of an `import myImage from '...'` directly as the first argument.","solutions":["Wrap the imported image in a src property: getImage({ src: importedImage }).","If using <Image />, use <Image src={importedImage} />, not <Image {...importedImage} />.","Audit MDX components that spread imported images into getImage.","Add a lint/type check that the first getImage argument is a transform, not an ImageMetadata."],"exampleFix":"// before\nimport photo from './photo.jpg';\nconst img = getImage(photo);\n\n// after\nimport photo from './photo.jpg';\nconst img = getImage({ src: photo, width: 800, height: 600 });","handlingStrategy":"type-guard","validationCode":"import { isImageMetadata } from 'astro/assets';\nfunction isBareImageMetadata(v: unknown): boolean {\n  return isImageMetadata(v);\n}","typeGuard":"import type { ImageMetadata } from 'astro';\nfunction isImageMetadataValue(v: unknown): v is ImageMetadata {\n  return typeof v === 'object' && v !== null && 'fsPath' in v;\n}","tryCatchPattern":null,"preventionTips":["Always wrap imported images: { src: imported }.","Review MDX components that spread imported images.","Add a type annotation that the first getImage argument is a transform."],"tags":["images","esm","api-misuse"],"backgroundTag":null,"analyzedSha":"d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca","analyzedAt":"2026-08-12T13:37:29.035Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}