I’m building a site using Astro 4.10.2. The site works great in dev, but I get a build error when trying to deploy the site. The error indicates that an image couldn’t be found, but the image exists and it works fine in dev.
This is what I have in the header of the failing Hero.astro (taken from here:
import { getImage } from 'astro:assets'
import myImage from './src/assets/images/image_xxl_25683256.jpg'
const optimizedBackgroundImage = await getImage({src: myImage});
and this is how the image is referenced in the body:
<section
class="min-h-screen bg-base-200 bg-cover bg-fixed bg-no-repeat"
style={`background-image: url('${optimizedBackgroundImage.src}')`}
>
This displays properly and without any error in dev.
In the Astro image documentation, I came across this statement
getImage() relies on server-only APIs and breaks the build when used on the client.
Maybe this is what I’m doing wrong, but the site is statically generated and I don’t understand “server-only API” and “client” in regards to a static site.
Can someone please help me get this site to build/deploy?