{"record":{"id":"9ff6520c61ece5fd","repo":"shadcn-ui/ui","slug":"no-components-json-found-run-shadcn-init-first","errorCode":null,"errorMessage":"No components.json found. Run shadcn init first.","messagePattern":"No components\\.json found\\. Run shadcn init first\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/shadcn/src/commands/registry/add.ts","lineNumber":80,"sourceCode":"        `Registry names must start with @ (e.g., @acme).`\n    )\n  }\n\n  return { namespace, url }\n}\n\nfunction pluralize(count: number, singular: string, plural: string) {\n  return `${count} ${count === 1 ? singular : plural}`\n}\n\nasync function addRegistriesToConfig(\n  registryArgs: string[],\n  cwd: string,\n  options: { silent?: boolean }\n) {\n  const configPath = path.resolve(cwd, \"components.json\")\n  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    }","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/shadcn-ui/ui/blob/efac5987074af84ece57c367c6dd83387b967022/packages/shadcn/src/commands/registry/add.ts#L62-L98","documentation":"addRegistriesToConfig requires an existing components.json in the cwd; without it there is nowhere to record the registry entry. Thrown before any network call is made.","triggerScenarios":"Running `shadcn registry add ...` in a directory that was never initialized with `shadcn init` (no components.json present at cwd).","commonSituations":"Wrong cwd, fresh project not yet initialized, components.json deleted or removed via git.","solutions":["Run `shadcn init` first.","Confirm you are in the project root: `ls components.json`.","Recreate components.json via init or restore it from git."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"import fs from \"fs\"\nimport path from \"path\"\n\nfunction assertComponentsJsonExists(cwd: string) {\n  if (!fs.existsSync(path.resolve(cwd, \"components.json\"))) {\n    throw new Error(\"Run `shadcn init` before adding registries.\")\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always run `shadcn init` before `shadcn registry add`.","Verify cwd contains components.json before invoking."],"tags":["registry","config","init"],"backgroundTag":null,"analyzedSha":"efac5987074af84ece57c367c6dd83387b967022","analyzedAt":"2026-08-12T05:00:50.218Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}