-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Description
Astro Info
Astro v5.17.2
Vite v6.4.1
Node v24.13.0
System Linux (x64)
Package Manager pnpm
Output static
Adapter none
Integrations none
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
When importing an image, either synchronously via import Image from '...', or async via import('...'), the final build output in dist/_astro contains the images even though no Astro-native image functions are used (e.g. getImage, or the Image/Picture components from astro:assets).
In the reproduction, I am only importing the image metadata itself, and process it manually into a base64 Data URI string. However, the final build output still contains a processed image (dist/_astro/example.C_B8VLaJ.png).
I replicated this with both, Astro 5 as well as the latest Astro 6 beta.
Curiously enough, this also happens when just importing an image to get its width or height, and not even touching its src property.
Why depend on ImageMetadata in the first place?
If I try to work around this via importing an image using the ?url query (e.g. import Image from './example.png?url'), Astro already processes the URL into something that points to the _astro/ folder (and not the original vite-internal module source).
What's the expected result?
Images that aren't actively used in the output should not appear in the final build output (as in, rendered to HTML).
Times when I expect images to be included:
-
When adding to the module graph via:
<img src={MyImage.src} />
-
When using the Astro-native
getImagemethod:const processedImg = await getImage({ src: MyImage, width: 200, height: 200, format: 'webp', })
-
When using the Astro-native
ImageandPicturecomponents (which usegetImageunder the hood, afaik). -
Manually calling the
emitImageMetadatafunction - as it implies we're "emit"-ing an asset.
Link to Minimal Reproducible Example
https://github.com/spaceemotion/astro-bug-incorrect-image-emits
Participation
- I am willing to submit a pull request for this issue.