{"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":72,"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":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/withastro/astro/blob/e294953aa8aadd98d5be92e60a03037b05dbdfd4/packages/astro/src/assets/internal.ts#L54-L90","documentation":"The ESM `import img from './img.png'` syntax produces an ImageMetadata object (with src/width/height/format). `getImage()` detects when that metadata object itself is passed as the whole options argument (`isImageMetadata(options)`, packages/astro/src/assets/internal.ts:70) and throws `ExpectedNotESMImage` — the image must be nested under `src`.","triggerScenarios":"`import hero from './hero.png'` followed by `getImage(hero)` instead of `getImage({ src: hero, ... })`; common when porting `<img src={hero.src}>`-style code or writing MDX where inlined imports return metadata objects.","commonSituations":"MDX files where an import expression resolves to the image metadata; refactors between `<img>` and `<Image>`; copying snippets that use `hero` directly as an attribute value.","solutions":["Wrap the import in an options object: `getImage({ src: hero, width: 800, height: 600 })`.","In MDX, prefer passing the import to `<Image src={hero} ... />` where the component accepts metadata directly.","If a function returns an image, `resolveSrc` inside `getImage` awaits it for you — just put it under `src`."],"exampleFix":"// before\nimport hero from './hero.png';\nconst img = await getImage(hero);\n\n// after\nimport hero from './hero.png';\nconst img = await getImage({ src: hero, width: 800, height: 600 });","handlingStrategy":"type-guard","validationCode":"import type { ImageMetadata } from 'astro';\n\nfunction isImageMetadata(value: unknown): value is ImageMetadata {\n  return (\n    typeof value === 'object' && value !== null &&\n    'src' in value && 'width' in value && 'height' in value && 'format' in value\n  );\n}\n\n// reject before calling: metadata must be nested under src\nif (isImageMetadata(options)) {\n  throw new TypeError('Pass the imported image as { src: image }, not as the options object');\n}","typeGuard":"function isImageMetadata(value: unknown): value is ImageMetadata {\n  return (\n    typeof value === 'object' && value !== null &&\n    typeof (value as any).src === 'string' &&\n    typeof (value as any).width === 'number' &&\n    typeof (value as any).height === 'number'\n  );\n}","tryCatchPattern":null,"preventionTips":["Standardize on getImage({ src: imported }) in code review checklists.","In MDX, prefer component syntax over script-block getImage calls."],"tags":["images","getimage","esm-import","api-usage"],"backgroundTag":"invalid-function-arguments","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"}