This document explains how image processing works in our Astro project and how we've configured it for both local development and Vercel deployment.
Astro uses Sharp as its default image processing library. When using a strict package manager like pnpm, Sharp must be installed manually as a dependency:
pnpm add sharpThis has been added to the project dependencies in package.json.
Our project uses Astro's built-in image optimization, configured in astro.config.mjs:
image: {
// Enable built-in image optimization
domains: [
'bun.sh',
'upload.wikimedia.org',
'avatars.githubusercontent.com',
'cdn.jsdelivr.net',
'pnpm.io',
]
}This configuration:
- Enables Astro's built-in image optimization
- Allows images from the specified domains to be optimized
When deploying to Vercel, the @astrojs/vercel adapter is used. This adapter is configured in astro.config.mjs:
adapter: vercel()For Vercel deployments, Sharp is required for image processing. Without Sharp installed, you'll encounter the following error:
MissingSharp: Could not find Sharp. Please install Sharp (`sharp`) manually into your project or migrate to another image service.
If you don't want to use Sharp for image processing, you can configure a passthrough image service in astro.config.mjs:
import { defineConfig, passthroughImageService } from "astro/config";
export default defineConfig({
image: {
service: passthroughImageService(),
},
});This will disable image processing entirely.
- Always include Sharp as a dependency in projects that use Astro's image optimization
- Store local images in the
src/directory for Astro to process them - Use the
<Image />component fromastro:assetsfor optimized images - For external images, ensure their domains are added to the
domainslist in the image configuration
If you encounter image processing issues:
- Verify Sharp is installed correctly:
pnpm add sharp - Check that the image domains are properly configured in astro.config.mjs
- For Vercel-specific issues, ensure the Vercel adapter is properly configured with
imageService: true - Check the
.vercelignorefile to ensure Sharp is not being excluded from deployment