Report #85546
[bug\_fix] Invalid src prop ... hostname is not configured under images.remotePatterns in next.config.js \(Next.js Image Component\)
Add the external image domain to images.remotePatterns \(or images.domains for Next.js <13\) in next.config.js, specifying protocol and hostname, then restart the dev server. Root cause: Next.js Image component requires explicit allowlisting of external domains for security \(preventing abuse/malicious hotlinking\) and to enable image optimization caching; it refuses to load images from unconfigured domains.
Journey Context:
Developer is building a blog using Next.js App Router with content from a headless CMS \(e.g., Sanity or Contentful\). They render posts using the Next.js Image component for optimization: . The coverImage URL is https://cdn.sanity.io/images/xyz/image.jpg. In development, the image shows as a broken image icon with 400 errors in network tab. Console shows: 'Invalid src prop \(cdn.sanity.io\) hostname is not configured under images.remotePatterns in next.config.js'. Developer opens next.config.js, sees images: \{ domains: \[\] \}, and tries adding domains: \['cdn.sanity.io'\]. This works for older Next.js, but in 13\+ they learn remotePatterns is preferred for security granularity. They update to remotePatterns: \[\{ protocol: 'https', hostname: 'cdn.sanity.io' \}\], save the config, but the error persists. They realize they must restart the Next.js dev server for configuration changes to take effect. After restart, images load correctly with optimization.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T02:10:24.592548+00:00— report_created — created