vercel/next.js · error

Specified assetPrefix is not a string, found type "${typeof

Error message

Specified assetPrefix is not a string, found type "${typeof result.assetPrefix}" https://nextjs.org/docs/messages/invalid-assetprefix

What it means

`assetPrefix` must be a string (or undefined to accept the default). After merging defaults with user config, normalization throws if `typeof result.assetPrefix !== 'string'`. This catches non-string values like numbers, objects, or booleans before they reach the asset URL builder.

Source

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

        Log.warn(
          'Specified "rewrites" will not automatically work with "output: export". See more info here: https://nextjs.org/docs/messages/export-no-custom-routes'
        )
      }
      if (result.redirects) {
        Log.warn(
          'Specified "redirects" will not automatically work with "output: export". See more info here: https://nextjs.org/docs/messages/export-no-custom-routes'
        )
      }
      if (result.headers) {
        Log.warn(
          'Specified "headers" will not automatically work with "output: export". See more info here: https://nextjs.org/docs/messages/export-no-custom-routes'
        )
      }
    }
  }

  if (typeof result.assetPrefix !== 'string') {
    throw new Error(
      `Specified assetPrefix is not a string, found type "${typeof result.assetPrefix}" https://nextjs.org/docs/messages/invalid-assetprefix`
    )
  }

  if (typeof result.basePath !== 'string') {
    throw new Error(
      `Specified basePath is not a string, found type "${typeof result.basePath}"`
    )
  }

  if (result.basePath !== '') {
    if (result.basePath === '/') {
      throw new Error(
        `Specified basePath /. basePath has to be either an empty string or a path prefix"`
      )
    }

    if (!result.basePath.startsWith('/')) {

View on GitHub (pinned to 0ae8c72462)

Solutions

  1. Set assetPrefix to a string URL: `assetPrefix: 'https://cdn.example.com'`
  2. Omit assetPrefix to use the default
  3. Coerce from env: `assetPrefix: typeof env === 'string' ? env : undefined`

Example fix

// before
module.exports = { assetPrefix: { url: 'https://cdn.example.com' } }
// after
module.exports = { assetPrefix: 'https://cdn.example.com' }
Defensive patterns

Strategy: type-guard

Validate before calling

if (assetPrefix !== undefined && typeof assetPrefix !== 'string') {
  throw new TypeError('assetPrefix must be a string')
}

Type guard

const isAssetPrefix = (v: unknown): v is string | undefined =>
  v === undefined || typeof v === 'string'

Prevention

When it happens

Trigger: Setting `assetPrefix: 123`, `assetPrefix: { cdn: 'https://...' }`, or `assetPrefix: true`. Triggered after the config merge in loadConfig.

Common situations: Passing a CDN URL loaded from a number-typed env var. Storing assetPrefix in an object and forgetting to dereference. Boolean flag meant to enable CDN.

Related errors


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