How do you allow external image domains in Next.js?

← Next.js answers

List the allowed hosts in images.remotePatterns in next.config.js. The older images.domains option still works but is deprecated.

// next.config.js
module.exports = {
  images: {
    remotePatterns: [
      {
        protocol: "https",
        hostname: "images.example.com",
        pathname: "/uploads/**",
      },
    ],
  },
};

Restart the dev server after changing the config. Patterns can match a path prefix, a port and wildcard subdomains, which lets you allow only what you need instead of a whole domain.

If the project uses a static export (output: "export"), the built-in image optimizer is not available, so set images.unoptimized to true.

Related questions

Start debugging smarter today

Try Bugsee for free — no commitments, no hidden fees.

Free sign upLive demoNo credit card required