vercel/next.js · error

Specified images.domains should be an Array received ${typeo

Error message

Specified images.domains should be an Array received ${typeof images.domains}.
See more info here: https://nextjs.org/docs/messages/invalid-images-config

What it means

`images.domains` (the legacy allow-list of remote hostnames as strings) must be an array if provided. The check at config.ts:750-756 rejects truthy non-arrays because the optimizer iterates the list. An unset value is allowed (no domains); only a wrong type throws.

Source

Thrown at packages/next/src/server/config.ts:752

          // avoid double-pushing the same pattern if it already can be matched
          if (!hasMatchForAssetPrefix) {
            images.remotePatterns.push({
              hostname: url.hostname,
              protocol: url.protocol.replace(/:$/, '') as 'http' | 'https',
              port: url.port,
            })
          }
        } catch (error) {
          throw new Error(
            `Invalid assetPrefix provided. Original error: ${error}`
          )
        }
      }
    }

    if (images.domains) {
      if (!Array.isArray(images.domains)) {
        throw new Error(
          `Specified images.domains should be an Array received ${typeof images.domains}.\nSee more info here: https://nextjs.org/docs/messages/invalid-images-config`
        )
      }
    }

    if (!images.loader) {
      images.loader = 'default'
    }

    if (
      images.loader !== 'default' &&
      images.loader !== 'custom' &&
      images.path === imageConfigDefault.path
    ) {
      throw new Error(
        `Specified images.loader property (${images.loader}) also requires images.path property to be assigned to a URL prefix.\nSee more info here: https://nextjs.org/docs/api-reference/next/legacy/image#loader-configuration`
      )
    }

View on GitHub (pinned to 0ae8c72462)

Solutions

  1. Use an array of strings: `domains: ['cdn.example.com', 'img.example.com']`.
  2. Prefer the newer `remotePatterns` for richer matching; `domains` is deprecated for new projects.
  3. Remove the key if no remote domains are needed.

Example fix

// before
module.exports = { images: { domains: 'cdn.example.com' } }
// after
module.exports = { images: { domains: ['cdn.example.com'] } }
Defensive patterns

Strategy: type-guard

Validate before calling

const d = config.images?.domains;
if (d != null && !Array.isArray(d)) throw new Error('images.domains must be an array of strings');
if (Array.isArray(d) && d.some((x) => typeof x !== 'string')) throw new Error('each domain must be a string');

Type guard

function isDomainsArray(v: unknown): v is string[] {
  return Array.isArray(v) && v.every((x) => typeof x === 'string');
}

Prevention

When it happens

Trigger: Setting `images: { domains: 'cdn.example.com' }` (string) or `domains: { host: 'cdn.example.com' }` (object).

Common situations: Confusing `domains` (array of plain hostname strings) with `remotePatterns` (array of objects). Supplying a single hostname string from a quick example.

Related errors


AI-assisted analysis of vercel/next.js@0ae8c72462 (2026-08-06). Data as JSON: /api/errors/25f1d4814c71ff10. Report an issue: GitHub.