Thomas Osayi

November 22, 2026 · 8 min read · Thomas Osayi

Fix the next/image "hostname is not configured" error in Next.js

Fix the next/image error that says a hostname is not configured under images in next.config.js, with remotePatterns examples for Supabase Storage and Firebase Storage.

You add a profile photo or product image from Supabase Storage or Firebase to a Next.js page, and instead of the image you get a red error overlay. In development it reads something like: Error: Invalid src prop (https://abcd1234.supabase.co/storage/v1/object/public/avatars/me.png) on next/image, hostname "abcd1234.supabase.co" is not configured under images in your next.config.js. In production the image simply fails with a 400.

The fix is a few lines in next.config.js. Getting those lines exactly right is the part that trips people up, especially in apps generated by v0, Cursor or Bolt, which often use the Image component without touching the config. Here is how it works and the patterns I use for the common hosts.

What does "hostname is not configured under images" mean?

It means you passed a remote URL to the next/image component, and that URL's host is not in the allowlist Next.js uses to decide which external images it will optimize.

The Image component does more than render an img tag. It sends the source through Next.js's image optimizer, which downloads the original, resizes it for the visitor's screen and converts it to a modern format. Because that optimizer fetches whatever URL it is given, an open optimizer could be abused to process arbitrary images on your server's dime. So Next.js refuses any remote image that does not match a pattern you explicitly allowed.

That allowlist lives in images.remotePatterns in next.config.js, or next.config.ts or next.config.mjs, depending on your project. Locally a mismatch shows the error overlay. In production, the Next.js docs state that any unmatched protocol, hostname, port or path responds with 400 Bad Request.

Local images in the public folder are not affected. This error is only about URLs that start with http or https.

How do I fix it with remotePatterns?

Add an entry to images.remotePatterns that matches the protocol, hostname, port and pathname of your image URLs, then restart the dev server.

There are two ways to write an entry.

The object form

This works in every recent Next.js version and is the one I recommend for storage providers. Inside images, add remotePatterns with an object containing protocol: 'https', hostname: 'assets.example.com', port: '' and a pathname such as '/account123/' followed by the two-asterisk wildcard, which Next.js reads as any number of path segments.

The URL form

Since Next.js 15.3 you can pass new URL() with the full pattern, for example the address of your bucket followed by the wildcard. It is shorter, but there is a catch covered below: when the URL has no search part, query strings are not allowed at all.

After editing the config, stop and restart next dev, because config changes are not hot reloaded. On Vercel, the change only takes effect after a new deployment.

Why does it still fail after I added the hostname?

Because matching is exact and case-sensitive across every part of the URL, so a single mismatched piece still fails the check.

The Next.js error documentation lists the usual suspects, and I see all of them:

  • Protocol mismatch: the pattern says http and the URL is https, or the reverse.
  • Subdomains: example.com does not match www.example.com or assets.example.com.
  • Ports: in local development, a URL like localhost:3000 needs the port in the pattern.
  • Pathname too narrow: a pattern of /images/ with no wildcard does not cover /images/2026/photo.jpg.
  • Query strings: with the URL form and no search part, any URL with a query string is rejected.
  • Wrong file: editing next.config.js when the project actually loads next.config.ts or next.config.mjs.
  • No restart or no redeploy after the change.

Wildcards can help with subdomains. Per the docs, a single asterisk matches one subdomain or path segment, and a double asterisk matches any number of subdomains at the beginning or path segments at the end, but not in the middle. So a hostname pattern of '*.supabase.co' covers any one project subdomain.

When none of that explains it, debug the match directly. Log the exact src value your component receives in the browser console, because generated code often builds URLs from environment variables, and a missing variable in production can produce a host like undefined or a relative path that suddenly looks remote. Compare that logged value piece by piece with your pattern: protocol, then hostname, then port, then the start of the path, then whether a query string is present. It feels tedious, but it usually takes two minutes and ends the guessing. If several environments use different storage projects, such as a staging Supabase project and a production one, each hostname needs its own entry.

What is the remotePatterns config for Supabase Storage?

Allow https, your project's hostname at supabase.co, and a pathname starting with /storage/v1/object/ so both public and signed URLs work.

Supabase documents the public URL format as your project ID at supabase.co, then /storage/v1/object/public/, then the bucket and file name. So the pattern is:

  • protocol: 'https'
  • hostname: 'abcd1234.supabase.co', using your own project reference
  • port: ''
  • pathname: '/storage/v1/object/public/' followed by the two-asterisk wildcard

If you use private buckets with signed URLs, those use a different segment after object and carry a token as a query string. Widen the pathname to '/storage/v1/object/' plus the wildcard, and use the object form without a search key so any query string is allowed.

Two Supabase-specific mistakes I run into:

  • A custom domain for Supabase changes the hostname, so the pattern must use the custom domain, not the supabase.co one.
  • Using a single asterisk subdomain pattern across all of supabase.co lets any Supabase project's public files through your optimizer. Pin your own project reference instead.

What is the remotePatterns config for Firebase Storage?

Allow https and the hostname firebasestorage.googleapis.com, with a pathname starting with /v0/b/ followed by your bucket name.

Download URLs returned by getDownloadURL in the Firebase web SDK point at firebasestorage.googleapis.com, with the bucket and the percent-encoded object path in the path, and a query string such as alt=media plus an access token. That query string is why the URL form of remotePatterns breaks here. Use the object form:

  • protocol: 'https'
  • hostname: 'firebasestorage.googleapis.com'
  • port: ''
  • pathname: '/v0/b/your-bucket-name/o/' followed by the wildcard

Leave out the search key so the token is accepted. Pinning the bucket name in the path matters for the same reason as with Supabase: firebasestorage.googleapis.com serves files for every Firebase project, and you only want yours.

Other hosts that show up in apps with social sign-in:

  • Google profile photos from Google sign-in usually come from lh3.googleusercontent.com.
  • Public Google Cloud Storage objects come from storage.googleapis.com.
  • Image CDNs like Cloudinary or Imgix each have their own hostname to add.

If you are wiring up Firebase sign-in in a Next.js app, "Firebase Authentication in the Next.js App Router: how to do it properly" covers the auth side.

Should I use unoptimized or allow all hostnames instead?

Use unoptimized only for specific images that should not go through the optimizer, and do not allow all hostnames in a real app.

The unoptimized prop serves the original file as is and skips the allowlist. The Next.js docs suggest it for images that require authentication, and SVGs are served unoptimized automatically when the source ends in .svg. It is a fine choice for a handful of special cases. It is a poor default, because you give up resizing and modern formats, which is the whole point of the component, and your pages get heavier. My post "Core Web Vitals explained for small business owners" explains why that matters for search.

Allowing every hostname with a double wildcard pattern makes the error disappear, and you will find it in a lot of AI-generated configs. The Next.js documentation warns against omitting parts of the pattern because it may allow malicious actors to optimize URLs you did not intend. On Vercel, image optimization usage counts toward your plan, so an open optimizer can also cost money.

The images.domains option you may see in old tutorials is deprecated since Next.js 14 and cannot restrict protocol, port or path. Replace it with remotePatterns when you touch the config.

What other next/image errors show up next?

Once the hostname is fixed, the next issues are usually missing dimensions, quality values or images on private networks.

  • Missing width and height: remote images need width and height props, or the fill prop inside a positioned parent, so Next.js can reserve space.
  • Quality values: Next.js 16 requires the qualities list in config, and a quality not in the list is coerced to the closest allowed value, with a warning in development.
  • Priority: in Next.js 16, the priority prop is deprecated in favour of preload or loading="eager" for above-the-fold images.
  • Local IPs: when self-hosting on a private network, images from local IP addresses are blocked by default, and dangerouslyAllowLocalIP exists for that rare case, with a real security trade-off.

If the error appears only after deploying, my post "Vercel build failed? The most common Next.js deploy errors and fixes" covers the build and environment issues that often travel with it.

What does the fix look like in a real project? A worked example

Here is an illustration with a made-up app: a gym's member portal generated in v0 and Cursor, with profile photos in a public Supabase bucket called avatars and class photos uploaded by staff through Firebase Storage from an older system.

The pages showed the hostname error for both. The config had an old images.domains entry for a stock photo site and nothing else. The fix was one remotePatterns array with two object entries: one for the project's supabase.co hostname with the /storage/v1/object/ pathname, and one for firebasestorage.googleapis.com pinned to the gym's bucket path, with no search key so Firebase tokens pass. The old domains entry became a third pattern. After a restart locally and a redeploy, both image types loaded, resized and in modern formats.

It took under an hour, including testing on the Vercel preview deployment. A fix like this fits my Quick Fix package from $60.

The bottom line

The next/image hostname error is Next.js protecting its image optimizer. Copy the exact failing URL, add a remotePatterns entry that matches its protocol, hostname, port and path, use the object form when URLs carry tokens, pin your own Supabase project or Firebase bucket, and restart or redeploy. Avoid allowing every host. If this is one of several things breaking in an AI-built Next.js app, my fix your AI-built app service is built for exactly that list.

Questions, answered in one line

Why does next/image say my hostname is not configured?

Because the image URL points to a host that does not match any entry in images.remotePatterns in next.config.js, so Next.js refuses to optimize it.

Should I use images.domains or remotePatterns?

Use remotePatterns, because the Next.js documentation marks images.domains as deprecated since Next.js 14 in favour of stricter remote patterns.

Why does the image work locally but return 400 in production?

Production returns 400 Bad Request for unmatched images, often because the production URL differs from the local one in protocol, hostname or query string, or the config change was never redeployed.

Can I just add the unoptimized prop to make the error go away?

Yes, unoptimized serves the image as is without the allowlist check, but you lose resizing and modern formats, so it suits only a few special cases.

Can someone fix image errors in my AI-built Next.js app?

Yes, Thomas Osayi fixes a single bug like this from $60 with his Quick Fix package, usually within two days.

Sources

About the author

Thomas Osayi is a full-stack developer in Los Angeles studying computer science at Loyola Marymount University. He founded and built SQWAD, a SaaS platform Shopify brands use to run creator programs, and builds custom Next.js websites, SaaS MVPs and fixes for AI-built apps for businesses and founders.

See his work · Services and prices

Related articles

Fix, finish and launch your AI-built app

Built your app with Lovable, Bolt, v0, Replit or Cursor and got stuck? I fix the bugs, connect auth and payments, clean up the code and deploy it to production.

See the service