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
- Set assetPrefix to a string URL: `assetPrefix: 'https://cdn.example.com'`
- Omit assetPrefix to use the default
- 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
- Coerce env-derived assetPrefix: `assetPrefix: typeof v === 'string' ? v : undefined`
- Type your config object against NextConfig
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
- Specified pageExtensions is not an array of strings, found "
- Specified basePath is not a string, found type "${typeof res
- `forbidden()` is experimental and only allowed to be enabled
- `unauthorized()` is experimental and only allowed to be used
- NEXT_EXPORT_ERROR
AI-assisted analysis of vercel/next.js@0ae8c72462 (2026-08-06).
Data as JSON: /api/errors/f949e8e1ce9230cb.
Report an issue: GitHub.