Next.js Image Optimization Error
Fix common Next.js Image Optimization errors including invalid src, missing domains config, and sharp installation issues.
What Does This Error Mean?
Next.js Image Optimization errors occur when the built-in Image component cannot process or optimize an image. This can be due to missing domain configuration, the optional sharp library, or invalid image sources.
Common Causes
Remote image domain not added to next.config.js images.domains
Sharp library not installed for production image optimization
Invalid image source (relative path instead of absolute or imported)
Missing width and height props on Image component
SVG files not allowed in Image optimization (use unoptimized)
External URL protocol not matching allowed patterns
How to Fix It
Configure remote image domains
Add all external image hosts to next.config.js.
// next.config.js
module.exports = {
images: {
remotePatterns: [
{
protocol: "https",
hostname: "images.example.com",
port: "",
pathname: "/**",
},
],
},
}Install sharp for production
Sharp is required for production image optimization on non-Vercel deployments.
# Install sharp npm install sharp # Verify installation npx sharp --version # Next.js will use sharp automatically when available # In development, Next.js uses squoosh (built-in)
Use proper Image component props
Always provide width, height, and alt attributes.
import Image from "next/image"
import myPic from "../public/photo.jpg"
// ✅ Imported image (automatic width/height)
<Image src={myPic} alt="Description" />
// ✅ Remote image with explicit dimensions
<Image
src="https://example.com/photo.jpg"
alt="Description"
width={800}
height={600}
/>
// ✅ Unoptimized for SVGs or dynamic images
<Image
src={svgImage}
alt="SVG"
width={100}
height={100}
unoptimized
/>Related Tools
Use these tools to debug and fix this error:
Related Errors
Other common errors in this category:
401 Unauthorized Error
Learn what a 401 Unauthorized error means, common causes, and how to fix authentication failures in your web applications.
403 Forbidden Error
Learn what 403 Forbidden means, how it differs from 401, and how to fix access denied errors in your applications.
404 Not Found Error
Learn what 404 Not Found means, common causes, and how to fix broken links and missing resources on your website or API.
429 Too Many Requests Error
Learn what 429 Too Many Requests means, how rate limiting works, and how to handle or avoid hitting API rate limits.