Next.jsImageError Fix2026 Updated
Next.js Image Component Not Working— Fixed [2026]
Also covers: hostname not configured · width and height required · fill layout issues
January 20265 min readNext.js 13–15 · App Router
⚡ Quick Fix — Add Hostname to next.config.js
next.config.js
module.exports = {
images: {
remotePatterns: [
{ protocol: 'https', hostname: 'images.unsplash.com' },
{ protocol: 'https', hostname: '**.cloudinary.com' },
],
},
}
// Restart dev server after changing next.config.jsCommon Next.js Image Errors
Error
Error: Invalid src prop on next/image, hostname "images.unsplash.com" is not configured under images in your next.config.js
Error: Image with src "/hero.jpg" has "fill" but is missing "sizes" prop. Please add it to improve page performance.
Error: Image with src "/photo.jpg" must use "width" and "height" properties or "fill" property.12 min
Configure External Hostname in next.config.js
Invalid src — hostname not configurednext.config.js
/** @type {import('next').NextConfig} */
const nextConfig = {
images: {
remotePatterns: [
{
protocol: 'https',
hostname: 'images.unsplash.com',
},
{
protocol: 'https',
hostname: '**.cloudinary.com', // wildcard for subdomains
},
{
protocol: 'https',
hostname: 's3.amazonaws.com',
pathname: '/my-bucket/**', // restrict to specific path
},
],
},
}
module.exports = nextConfigAlways restart your Next.js dev server after changing next.config.js. The change will not take effect until you do.
21 min
Always Provide Width and Height
Missing dimensions — prevents layout shiftcomponents/ProductImage.jsx
import Image from 'next/image'
// ❌ WRONG — missing dimensions
<Image src="/product.jpg" alt="Product" />
// ✅ CORRECT — explicit dimensions
<Image
src="/product.jpg"
alt="Product photo"
width={800}
height={600}
/>
// ✅ For local imports — dimensions auto-detected
import productImg from '/public/product.jpg'
<Image src={productImg} alt="Product photo" />33 min
Fill Layout for Responsive Images
Image filling its containercomponents/HeroBanner.jsx
import Image from 'next/image'
// ✅ Parent must be position: relative with defined height
export default function HeroBanner() {
return (
<div style={{ position: 'relative', height: '500px', width: '100%' }}>
<Image
src="/hero.jpg"
alt="Hero banner"
fill
style={{ objectFit: 'cover' }}
sizes="100vw"
priority // add for above-the-fold images
/>
</div>
)
}
// ✅ With Tailwind
<div className="relative h-64 w-full">
<Image src="/hero.jpg" alt="Hero" fill className="object-cover" sizes="100vw" />
</div>41 min
Local Images — Correct Import Pattern
Images from public/ or src/ directorycomponents/Logo.jsx
import Image from 'next/image'
// ✅ Option A — import from /public (use string path)
<Image src="/logo.png" width={120} height={40} alt="Logo" />
// ✅ Option B — import as module (auto width/height)
import logo from '@/public/logo.png'
<Image src={logo} alt="Logo" />
// ✅ Option C — import from src/assets
import avatar from '@/assets/avatar.jpg'
<Image src={avatar} alt="Avatar" />
// ❌ WRONG — absolute file system path
<Image src="/Users/me/project/public/logo.png" alt="Logo" />52 min
Image Not Showing — CSS Parent Issue
Image renders in DOM but is invisibleIf the image is in the DOM (visible in DevTools) but not on screen, the parent container has overflow: hidden or height: 0.
Diagnosis
/* Check parent in DevTools:
- height: 0 or auto with no content → add explicit height
- overflow: hidden → may be clipping the image
- position not relative → fill images need relative parent */
// ✅ Fix — ensure parent has height
<div className="relative h-48 overflow-hidden rounded-lg">
<Image src={src} fill alt={alt} className="object-cover" sizes="(max-width: 768px) 100vw, 50vw" />
</div>Prevention
- Add all external image hostnames to remotePatterns in next.config.js on day one
- Always provide width and height — or use fill with a positioned parent
- Add priority to any above-the-fold image (hero, banner, LCP element)
- Add sizes prop to fill images for correct responsive behavior
- Import local images as modules when possible — Next.js auto-detects dimensions
Frequently Asked Questions
Next.js Image: hostname not configured in next.config.js error?+−
Add the external domain to remotePatterns in next.config.js: images: { remotePatterns: [{ protocol: 'https', hostname: 'images.example.com' }] }. Restart your dev server after changing next.config.js.
Next.js Image requires width and height — how to fix?+−
Always provide width and height props unless using fill: <Image src={src} width={800} height={600} alt='description' />. These are required so Next.js can reserve space before the image loads, preventing layout shift.
How do I make Next.js Image fill its parent container?+−
Add fill prop and make the parent position: relative with a defined height: <div style={{ position: 'relative', height: '400px' }}><Image src={src} fill alt='...' style={{ objectFit: 'cover' }} /></div>
Next.js Image not displaying in production but works locally?+−
Your image domain is not in remotePatterns in next.config.js, or the image path is wrong in the deployed environment. Check that all external hostnames are configured and that local images are in the public/ folder or imported correctly.
Can I use next/image with any external URL?+−
No. For security, Next.js requires you to explicitly whitelist external domains in next.config.js remotePatterns. This prevents your image optimization endpoint from being used as a proxy for arbitrary URLs.
Next.js Image blurDataURL error — how to fix?+−
If using placeholder='blur' with a remote image, you must provide a blurDataURL: <Image src={url} placeholder='blur' blurDataURL='/placeholder.png' width={800} height={600} alt='...' />. For local images, blurDataURL is auto-generated.
Need Expert Help?
We Build Production-Grade Next.js Apps
Softplix builds full-stack Next.js applications. Need help with image optimisation or performance? We can help.
Talk to an Engineer