diff --git a/packages/astro/src/assets/services/service.ts b/packages/astro/src/assets/services/service.ts index 9cd6d0ecba42c..0547757c517ef 100644 --- a/packages/astro/src/assets/services/service.ts +++ b/packages/astro/src/assets/services/service.ts @@ -3,7 +3,7 @@ import { AstroError, AstroErrorData } from '../../core/errors/index.js'; import { isRemotePath, joinPaths } from '../../core/path.js'; import { DEFAULT_HASH_PROPS, DEFAULT_OUTPUT_FORMAT, VALID_SUPPORTED_FORMATS } from '../consts.js'; import type { ImageOutputFormat, ImageTransform, UnresolvedSrcSetValue } from '../types.js'; -import { isESMImportedImage } from '../utils/imageKind.js'; +import { isESMImportedImage, isRemoteImage } from '../utils/imageKind.js'; import { isRemoteAllowed } from '../utils/remotePattern.js'; export type ImageService = LocalImageService | ExternalImageService; @@ -142,7 +142,7 @@ export const baseService: Omit = { propertiesToHash: DEFAULT_HASH_PROPS, validateOptions(options) { // `src` is missing or is `undefined`. - if (!options.src || (typeof options.src !== 'string' && typeof options.src !== 'object')) { + if (!options.src || (!isRemoteImage(options.src) && !isESMImportedImage(options.src))) { throw new AstroError({ ...AstroErrorData.ExpectedImage, message: AstroErrorData.ExpectedImage.message( diff --git a/packages/astro/src/assets/utils/imageKind.ts b/packages/astro/src/assets/utils/imageKind.ts index 7b42f9f7017f3..7dc911e0265e4 100644 --- a/packages/astro/src/assets/utils/imageKind.ts +++ b/packages/astro/src/assets/utils/imageKind.ts @@ -1,7 +1,7 @@ import type { ImageMetadata, UnresolvedImageTransform } from '../types.js'; export function isESMImportedImage(src: ImageMetadata | string): src is ImageMetadata { - return typeof src === 'object'; + return typeof src === 'object' || (typeof src === 'function' && 'src' in src); } export function isRemoteImage(src: ImageMetadata | string): src is string {