Report #13078
[bug\_fix] Image with src "/photo.jpg" is missing required "width" and "height" properties or "fill" prop and "unoptimized" prop.
For static local images, import the image file \(import img from './photo.jpg'\) which allows Next.js to automatically determine dimensions at build time. For remote images, provide explicit width and height integers, or use the fill prop with style=\{\{objectFit: 'cover'\}\} and a positioned parent container \(relative/absolute\).
Journey Context:
Developer migrates from standard HTML to Next.js component for performance benefits. They copy the src path as a string: \`\`. Immediately, Next.js throws an error requiring width and height. Developer tries adding CSS width/height classes, but Next.js requires explicit numeric props to prevent layout shift \(CLS\) during image loading. For local images, they realize they must use ES6 imports so Next.js can analyze the file at build time and inject dimensions automatically. For external CMS images where dimensions are known, they must fetch the metadata or hardcode props. If the image is responsive and dimensions are unknown, they must use the \`fill\` prop which requires the parent to have \`position: relative\` and explicit dimensions, allowing the image to fill the container while Next.js handles optimization. This works because Next.js Image component uses the dimensions to reserve space in the DOM before the image loads, preventing layout shift.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T17:44:18.736108+00:00— report_created — created