{"record":{"id":"066cf92d68d28cf0","repo":"shadcn-ui/ui","slug":"no-highlighter-info-components-json-or-hig","errorCode":null,"errorMessage":"No ${highlighter.info(\"components.json\")} or ${highlighter.info(\"package.json\")} found. Run ${highlighter.info(\"shadcn init\")} first.","messagePattern":"No (.+?) or (.+?) found\\. Run (.+?) first\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/shadcn/src/commands/registry/add.ts","lineNumber":85,"sourceCode":"}\n\nfunction pluralize(count: number, singular: string, plural: string) {\n  return `${count} ${count === 1 ? singular : plural}`\n}\n\nexport async function addRegistriesToConfig(\n  registryArgs: string[],\n  cwd: string,\n  options: { silent?: boolean }\n) {\n  // Write to components.json when it exists, otherwise fall back to\n  // package.json. This mirrors how registries are resolved.\n  const configPath = [\"components.json\", \"package.json\"]\n    .map((file) => path.resolve(cwd, file))\n    .find((file) => fs.existsSync(file))\n\n  if (!configPath) {\n    throw new Error(\n      `No ${highlighter.info(\"components.json\")} or ${highlighter.info(\n        \"package.json\"\n      )} found. Run ${highlighter.info(\"shadcn init\")} first.`\n    )\n  }\n\n  const configFileName = path.basename(configPath)\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()","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/shadcn-ui/ui/blob/c06da1d0e91e97b607d1359372347528bb35b090/packages/shadcn/src/commands/registry/add.ts#L67-L103","documentation":"Thrown by addRegistriesToConfig, the function behind `shadcn registry add`. The command persists registered registries into either components.json or package.json, and it locates them by checking fs.existsSync on both files in the target cwd. If neither file exists there, there is nowhere to write the registry entry, so the CLI aborts and tells you to run `shadcn init` first.","triggerScenarios":"Running `npx shadcn@latest registry add @acme=https://example.com/r/{name}.json` in a directory that contains neither components.json nor package.json — e.g. an empty folder, a non-Node project root, a random subdirectory, or passing `-c/--cwd` that points at the wrong path. Also hit when calling the exported addRegistriesToConfig(registryArgs, cwd) programmatically with a cwd that has no config file.","commonSituations":"Running the command from a fresh directory before ever running `shadcn init`; running it one level off the project root in a monorepo; a typo in --cwd; CI or tooling invoking the API against a scratch directory.","solutions":["Run the command from a directory that already has a package.json (usually the project root), or pass the correct path: `npx shadcn@latest registry add -c path/to/project @acme=...`.","If the project was never initialized, run `npx shadcn@latest init` first to create components.json, then retry the registry add.","In a non-Node directory, create a minimal package.json (name + version) so the CLI has a place to record the `registries` field."],"exampleFix":"// before (run in an empty directory)\nnpx shadcn@latest registry add @acme=https://acme.com/r/{name}.json\n// -> No components.json or package.json found. Run shadcn init first.\n\n// after\ncd my-app                          # directory containing package.json\nnpx shadcn@latest init             # only if components.json does not exist yet\nnpx shadcn@latest registry add @acme=https://acme.com/r/{name}.json","handlingStrategy":"validation","validationCode":"import { existsSync } from 'fs'\nimport path from 'path'\n\n// Run before invoking `shadcn registry add` or addRegistriesToConfig().\nfunction canAddRegistries(cwd: string): boolean {\n  return (\n    existsSync(path.resolve(cwd, 'components.json')) ||\n    existsSync(path.resolve(cwd, 'package.json'))\n  )\n}\n\nif (!canAddRegistries(process.cwd())) {\n  console.error('Initialize the project first: npx shadcn@latest init')\n  process.exit(1)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always run `shadcn registry add` from the project root (the folder with package.json) or pass -c/--cwd explicitly.","Run `npx shadcn@latest init` once per project before using registry subcommands.","In scripts, assert the config file exists before shelling out to the CLI."],"tags":["shadcn","cli","config","registry","project-init"],"backgroundTag":"missing-config-file","analyzedSha":"c06da1d0e91e97b607d1359372347528bb35b090","analyzedAt":"2026-08-21T17:08:35.471Z","contentChangedAt":"2026-08-21T17:08:35.471Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}