Report #90349
[bug\_fix] Next.js Image component requires width and height or fill prop for local images with string src
Next.js Image optimization requires knowing the aspect ratio to prevent Layout Shift \(CLS\). For local images imported statically \(import img from './img.jpg'\), Next.js analyzes the file at build time and provides width/height automatically. However, if using a string path \(src="/img.jpg"\), Next.js cannot safely introspect the file system at build time in all deployment scenarios \(especially with remote caching or serverless functions\), so it requires explicit width and height attributes. Alternatively, the fill prop can be used, which causes the image to fill the parent element \(which must have position: relative and defined dimensions\).
Journey Context:
Developer places hero.png in the public/ folder. In their page component, they write . They assume Next.js handles everything automatically. Upon running next dev, they get a hard error overlay: "Image with src /hero.png must use fill prop or have width and height". Confused because they thought Next.js auto-detects. Realizes auto-detection only works with static imports. They don't want to import because path is dynamic from CMS \(but in this case it's static\). They measure the image \(800x600\) and add width=\{800\} height=\{600\} manually. Error resolved. Later, they try to make it responsive and switch to the fill prop with sizes="100vw" and a relative parent container.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T10:14:45.663408+00:00— report_created — created