{"record":{"id":"d821354455e91f15","repo":"vercel/next.js","slug":"cannot-prefetch-href-because-it-cannot-be-con","errorCode":null,"errorMessage":"Cannot prefetch '${href}' because it cannot be converted to a URL.","messagePattern":"Cannot prefetch '(.+?)' because it cannot be converted to a URL\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/next/src/client/components/app-router-utils.ts","lineNumber":27,"sourceCode":" * Given a link href, constructs the URL that should be prefetched. Returns null\n * in cases where prefetching should be disabled, like external URLs, or\n * during development.\n * @param href The href passed to <Link>, router.prefetch(), or similar\n * @returns A URL object to prefetch, or null if prefetching should be disabled\n */\nexport function createPrefetchURL(href: string): URL | null {\n  // Don't prefetch for bots as they don't navigate.\n  if (isBot(window.navigator.userAgent)) {\n    return null\n  }\n\n  let url: URL\n  try {\n    url = new URL(addBasePath(href), window.location.href)\n  } catch (_) {\n    // TODO: Does this need to throw or can we just console.error instead? Does\n    // anyone rely on this throwing? (Seems unlikely.)\n    throw new Error(\n      `Cannot prefetch '${href}' because it cannot be converted to a URL.`\n    )\n  }\n\n  // Don't prefetch during development (improves compilation performance)\n  if (process.env.NODE_ENV === 'development') {\n    return null\n  }\n\n  // External urls can't be prefetched in the same way.\n  if (isExternalURL(url)) {\n    return null\n  }\n\n  return url\n}\n","sourceCodeStart":9,"sourceCodeEnd":44,"githubUrl":"https://github.com/vercel/next.js/blob/0eb377541648e63402a47b38fee00a8d0ce8f8f1/packages/next/src/client/components/app-router-utils.ts#L9-L44","documentation":"Defense in createPrefetchURL: constructing a URL from the link href (with base path applied) threw, meaning the href is not resolvable to a valid URL. The error is raised from that catch block; prefetch for this href is impossible and callers like router.prefetch surface the failure.","triggerScenarios":"Prefetch is requested for an href that cannot be parsed into a URL.","commonSituations":"A Link or prefetch call receives a malformed or non-URL string such as an external scheme.","solutions":["Pass a valid, URL-parseable href to prefetch(); remove prefetch on invalid or empty hrefs."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"0eb377541648e63402a47b38fee00a8d0ce8f8f1","analyzedAt":"2026-08-19T02:10:13.922Z","contentChangedAt":"2026-08-19T02:10:13.922Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}