-
-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: Using Image
component and image server returns error
#128
Comments
I was aware of those 2 issues, so I didn't expect it to work with sharp or swoosh, however I'm surprised it doesn't work with the passthrough image service as that doesn't/shouldn't do any image optimisation? Admittedly, I know nothing about the internals of astro though! |
It looks like we will have to implement |
I've just realised that of course this doesn't work - the default image service sets the url to This probably just needs a custom image service which replaces the url with just what's used for the I'll try to throw a PoC together to give this a try. |
I've managed to throw together a very barebones POC that works for us (stick this file in your astro root alongside your astro config file): // image_service.ts
import type { ExternalImageService } from "astro";
const imageService: ExternalImageService<{}> = {
getURL(options, imageConfig) {
// Because this doesn't support transforming, we can discard anything that isn't the src attribute
return typeof options.src === "object" ? options.src.src : options.src;
},
getHTMLAttributes(options, imageConfig) {
const { src, format, quality, ...attributes } = options;
return {
...attributes,
loading: options.loading ?? "lazy",
decoding: options.decoding ?? "async",
};
},
};
export default imageService; Then updated our export default defineConfig({
...
image: {
service: {
entrypoint: "./image_service",
},
},
}) Hopefully this helps for building an actual solution! |
💻
Input code
Something like this:
Current and expected behavior
During build the
src
attribute is correctly set to use the image server (eg,/_image?href=%2F_astro%2Fimage.Y0Z6qWya.png&f=webp
), but when rendering the lambda returns a 500 error, rather than the image itself.In the server logs, we see this error:
Environment
Possible solution
No response
Additional context
I originally wondered if this was an issue with using sharp or swoosh, so followed the docs to just use a passthrough service but that didn't seem to help.
For now, we're able to bypass this by using an
img
tag and referencing thesrc
attribute:The text was updated successfully, but these errors were encountered: