vercel/next.js · error

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

Error message

Specified basePath is not a string, found type "${typeof result.basePath}"

What it means

`basePath` must be a string (or undefined). After config merge, normalization throws if `typeof result.basePath !== 'string'`, catching numbers, objects, booleans, etc. before the basePath is used to prefix every route.

Source

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

          '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('/')) {
      throw new Error(
        `Specified basePath has to start with a /, found "${result.basePath}"`
      )
    }

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

View on GitHub (pinned to 0ae8c72462)

Solutions

  1. Set basePath to a string path like `basePath: '/docs'`
  2. Omit basePath to default to '' (root)
  3. Coerce safely: `basePath: typeof env === 'string' ? env : undefined`

Example fix

// before
module.exports = { basePath: 123 }
// after
module.exports = { basePath: '/docs' }
Defensive patterns

Strategy: type-guard

Validate before calling

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

Type guard

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

Prevention

When it happens

Trigger: Setting `basePath: 123`, `basePath: true`, or `basePath: { prefix: '/docs' }`. Checked after the assetPrefix check in loadConfig.

Common situations: Reading basePath from a non-string env var. Constructing basePath conditionally and leaving a truthy non-string. Accidentally assigning an object.

Related errors


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