{"record":{"id":"ef84d86fbe21cad2","repo":"vercel/next.js","slug":"invalid-assetprefix-provided-original-error-er","errorCode":null,"errorMessage":"Invalid assetPrefix provided. Original error: ${error}","messagePattern":"Invalid assetPrefix provided\\. Original error: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/next/src/server/config.ts","lineNumber":743,"sourceCode":"      // so we need to ensure _next/image allows downloading from\n      // this resource\n      if (config.assetPrefix?.startsWith('http')) {\n        try {\n          const url = new URL(config.assetPrefix)\n          const hasMatchForAssetPrefix = images.remotePatterns.some((pattern) =>\n            matchRemotePattern(pattern, url)\n          )\n\n          // avoid double-pushing the same pattern if it already can be matched\n          if (!hasMatchForAssetPrefix) {\n            images.remotePatterns.push({\n              hostname: url.hostname,\n              protocol: url.protocol.replace(/:$/, '') as 'http' | 'https',\n              port: url.port,\n            })\n          }\n        } catch (error) {\n          throw new Error(\n            `Invalid assetPrefix provided. Original error: ${error}`\n          )\n        }\n      }\n    }\n\n    if (images.domains) {\n      if (!Array.isArray(images.domains)) {\n        throw new Error(\n          `Specified images.domains should be an Array received ${typeof images.domains}.\\nSee more info here: https://nextjs.org/docs/messages/invalid-images-config`\n        )\n      }\n    }\n\n    if (!images.loader) {\n      images.loader = 'default'\n    }\n","sourceCodeStart":725,"sourceCodeEnd":761,"githubUrl":"https://github.com/vercel/next.js/blob/0ae8c72462952df163f1b1e0726641bc5b40dc93/packages/next/src/server/config.ts#L725-L761","documentation":"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.","triggerScenarios":"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`.","commonSituations":"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.","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."],"exampleFix":"// before\nmodule.exports = { assetPrefix: 'http://', images: { remotePatterns: [{ hostname: 'cdn.example.com' }] } }\n// after\nmodule.exports = { assetPrefix: 'https://cdn.example.com', images: { remotePatterns: [{ hostname: 'cdn.example.com' }] } }","handlingStrategy":"validation","validationCode":"if (config.assetPrefix && config.assetPrefix.startsWith('http')) {\n  try { new URL(config.assetPrefix); } catch (e) { throw new Error('assetPrefix is not a valid URL: ' + config.assetPrefix); }\n}","typeGuard":"function isParseableHttpUrl(v: unknown): boolean {\n  if (typeof v !== 'string' || !v.startsWith('http')) return true; // non-http prefixes skip this check\n  try { new URL(v); return true; } catch { return false; }\n}","tryCatchPattern":"try { new URL(config.assetPrefix); } catch (e) { throw new Error(`Invalid assetPrefix provided. Original error: ${e}`); }","preventionTips":["Validate templated assetPrefix values with `new URL()` before committing config.","Ensure env vars interpolated into assetPrefix are set and non-empty at build time."],"tags":["config","images","assetprefix","url-parsing","next-config"],"analyzedSha":"0ae8c72462952df163f1b1e0726641bc5b40dc93","analyzedAt":"2026-08-06T19:44:29.143Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}