vercel/next.js · error
Invalid assetPrefix provided. Original error: ${error}
Error message
Invalid assetPrefix provided. Original error: ${error} What it means
When `images.remotePatterns` is set AND `config.assetPrefix` starts with 'http', Next.js tries `new URL(config.assetPrefix)` to auto-add a remote pattern for the asset host (config.ts:727-746). If `new URL()` throws because the assetPrefix is not parseable as a URL, the catch wraps it in this error. This protects the optimizer from registering a malformed remote target.
Source
Thrown at packages/next/src/server/config.ts:743
// so we need to ensure _next/image allows downloading from
// this resource
if (config.assetPrefix?.startsWith('http')) {
try {
const url = new URL(config.assetPrefix)
const hasMatchForAssetPrefix = images.remotePatterns.some((pattern) =>
matchRemotePattern(pattern, url)
)
// 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'
}
View on GitHub (pinned to 0ae8c72462)
Solutions
- Make assetPrefix a fully-qualified, parseable URL: `assetPrefix: 'https://cdn.example.com'`.
- If assetPrefix is a path prefix (not a host), do not start it with 'http'.
- Ensure any env vars interpolated into assetPrefix are set and non-empty.
Example fix
// before
module.exports = { assetPrefix: 'http://', images: { remotePatterns: [{ hostname: 'cdn.example.com' }] } }
// after
module.exports = { assetPrefix: 'https://cdn.example.com', images: { remotePatterns: [{ hostname: 'cdn.example.com' }] } } Defensive patterns
Strategy: validation
Validate before calling
if (config.assetPrefix && config.assetPrefix.startsWith('http')) {
try { new URL(config.assetPrefix); } catch (e) { throw new Error('assetPrefix is not a valid URL: ' + config.assetPrefix); }
} Type guard
function isParseableHttpUrl(v: unknown): boolean {
if (typeof v !== 'string' || !v.startsWith('http')) return true; // non-http prefixes skip this check
try { new URL(v); return true; } catch { return false; }
} Try / catch
try { new URL(config.assetPrefix); } catch (e) { throw new Error(`Invalid assetPrefix provided. Original error: ${e}`); } Prevention
- Validate templated assetPrefix values with `new URL()` before committing config.
- Ensure env vars interpolated into assetPrefix are set and non-empty at build time.
When it happens
Trigger: Setting `assetPrefix: 'http://'` (empty host), `assetPrefix: 'http://[invalid'` (bad bracket), `assetPrefix: 'http://exa mple.com'` (space), or any assetPrefix starting with 'http' that is not a valid absolute URL, while also defining `images.remotePatterns`.
Common situations: Using a templated assetPrefix (e.g. `http://${BUCKET}`) where the env var is empty at build time. Typos in CDN URLs. Combining a custom assetPrefix with remotePatterns for the first time.
Related errors
- Specified images should be an object received ${typeof image
- Specified images.localPatterns should be an Array received $
- Specified images.remotePatterns should be an Array received
- Specified images.remotePatterns must have protocol "http" or
- Specified images.domains should be an Array received ${typeo
AI-assisted analysis of vercel/next.js@0ae8c72462 (2026-08-06).
Data as JSON: /api/errors/ef84d86fbe21cad2.
Report an issue: GitHub.