{"record":{"id":"fed7b96f7b9bd4f9","repo":"shadcn-ui/ui","slug":"failed-to-fetch-registries","errorCode":null,"errorMessage":"Failed to fetch registries.","messagePattern":"Failed to fetch registries\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/shadcn/src/commands/registry/add.ts","lineNumber":97,"sourceCode":"  if (!fs.existsSync(configPath)) {\n    throw new Error(\n      `No ${highlighter.info(\"components.json\")} found. Run ${highlighter.info(\n        \"shadcn init\"\n      )} first.`\n    )\n  }\n\n  const parsed = registryArgs.map(parseRegistryArg)\n  const needsLookup = parsed.filter((p) => !p.url)\n  let registriesIndex: { name: string; url: string }[] = []\n  if (needsLookup.length > 0) {\n    const fetchSpinner = spinner(\"Fetching registries.\", {\n      silent: options.silent,\n    }).start()\n    const registries = await getRegistries()\n    if (!registries) {\n      fetchSpinner.fail()\n      throw new Error(\"Failed to fetch registries.\")\n    }\n    fetchSpinner.succeed()\n    registriesIndex = registries\n  }\n\n  const registriesToAdd: Record<string, string> = {}\n  for (const { namespace, url } of parsed) {\n    if (namespace in BUILTIN_REGISTRIES) {\n      logger.warn(\n        `${highlighter.info(\n          namespace\n        )} is a built-in registry and cannot be added.`\n      )\n      continue\n    }\n\n    if (url) {\n      if (!url.includes(\"{name}\")) {","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/shadcn-ui/ui/blob/efac5987074af84ece57c367c6dd83387b967022/packages/shadcn/src/commands/registry/add.ts#L79-L115","documentation":"When at least one registry arg lacks an explicit URL, the CLI calls getRegistries() to look up the official index. If that returns null — network error, non-200, or unparseable response — the spinner fails and this throws.","triggerScenarios":"Running `shadcn registry add @somename` (no inline URL) while offline, behind a blocking proxy, or when the shadcn registries endpoint is unreachable or returns invalid JSON.","commonSituations":"No internet, corporate proxy/firewall blocking ui.shadcn.com, DNS failure, endpoint temporarily down, response schema change between versions.","solutions":["Provide the URL explicitly to skip the lookup: `shadcn registry add @acme=https://example.com/r/{name}.json`.","Check connectivity to the shadcn registry host.","Retry; the endpoint may be transiently unavailable.","Configure HTTP_PROXY / HTTPS_PROXY if behind a corporate network."],"exampleFix":"// before\nshadcn registry add @acme\n// after (offline-safe)\nshadcn registry add @acme=https://my-cdn.example.com/r/{name}.json","handlingStrategy":"fallback","validationCode":"// Skip the network lookup by always supplying an explicit URL template.\nconst arg = `@acme=https://my-cdn.example.com/r/{name}.json`","typeGuard":null,"tryCatchPattern":"try {\n  await addRegistriesToConfig([\"@acme\"], cwd, {})\n} catch (e) {\n  if (e instanceof Error && /Failed to fetch registries/.test(e.message)) {\n    // Fallback: supply the URL inline to avoid the index lookup.\n    return addRegistriesToConfig([\"@acme=https://my-cdn.example.com/r/{name}.json\"], cwd, {})\n  }\n  throw e\n}","preventionTips":["Pin registry URLs in components.json so future adds skip the network lookup.","Add retry/backoff around registry fetches when running in CI."],"tags":["network","registry","fetch"],"backgroundTag":null,"analyzedSha":"efac5987074af84ece57c367c6dd83387b967022","analyzedAt":"2026-08-12T05:00:50.218Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}