diff --git a/.changeset/lazy-flowers-destroy.md b/.changeset/lazy-flowers-destroy.md new file mode 100644 index 000000000000..b08525b18401 --- /dev/null +++ b/.changeset/lazy-flowers-destroy.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +fix: improve error message when inferSize is used in local images with the Image component diff --git a/packages/astro/src/assets/internal.ts b/packages/astro/src/assets/internal.ts index 4cc85799c154..58cd41f43235 100644 --- a/packages/astro/src/assets/internal.ts +++ b/packages/astro/src/assets/internal.ts @@ -1,3 +1,4 @@ +import { isRemotePath } from '@astrojs/internal-helpers/path'; import type { AstroConfig } from '../@types/astro.js'; import { AstroError, AstroErrorData } from '../core/errors/index.js'; import { DEFAULT_HASH_PROPS } from './consts.js'; @@ -65,7 +66,11 @@ export async function getImage( }; // Infer size for remote images if inferSize is true - if (options.inferSize && isRemoteImage(resolvedOptions.src)) { + if ( + options.inferSize && + isRemoteImage(resolvedOptions.src) && + isRemotePath(resolvedOptions.src) + ) { const result = await inferRemoteSize(resolvedOptions.src); // Directly probe the image URL resolvedOptions.width ??= result.width; resolvedOptions.height ??= result.height;