{"record":{"id":"7695b0390616156d","repo":"shadcn-ui/ui","slug":"failed-to-read-config-at-options-cwd","errorCode":null,"errorMessage":"Failed to read config at ${options.cwd}.","messagePattern":"Failed to read config at (.+?)\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/shadcn/src/commands/add.ts","lineNumber":274,"sourceCode":"          defaults: false,\n          skipPreflight: true,\n          silent: !hasNewRegistries && options.silent,\n          isNewProject: true,\n          cssVariables: true,\n          rtl: false,\n          installStyleIndex,\n          components: [cleanInitUrl, ...(options.components ?? [])],\n          registryBaseConfig,\n        })\n        initHasRun = true\n\n        shouldUpdateAppIndex =\n          options.components?.length === 1 &&\n          !!options.components[0].match(/\\/chat\\/b\\//)\n      }\n\n      if (!config) {\n        throw new Error(\n          `Failed to read config at ${highlighter.info(options.cwd)}.`\n        )\n      }\n\n      const { config: updatedConfig } = await ensureRegistriesInConfig(\n        options.components,\n        config,\n        {\n          silent: options.silent || hasNewRegistries,\n          writeFile: !isDryRun,\n        }\n      )\n      config = updatedConfig\n\n      // Dry-run mode: preview changes without writing files.\n      // --diff and --view imply --dry-run.\n      if (isDryRun) {\n        const dryRunSpinner = spinner(\"Resolving items.\", {","sourceCodeStart":256,"sourceCodeEnd":292,"githubUrl":"https://github.com/shadcn-ui/ui/blob/efac5987074af84ece57c367c6dd83387b967022/packages/shadcn/src/commands/add.ts#L256-L292","documentation":"In the `shadcn add` command, after the optional init path, if no components.json config could be loaded (config still falsy), it throws pointing at options.cwd. It means neither an existing config was read nor did runInit produce one, so there is no target project to add components into.","triggerScenarios":"Running `shadcn add` in a directory without components.json with init skipped or failed; passing a --cwd that does not exist or lacks a config; file permissions preventing the read.","commonSituations":"First run in a fresh project where init was bypassed; wrong cwd in CI; corrupted or missing components.json.","solutions":["Run `shadcn init` first (or allow add to trigger init) to create components.json.","Confirm --cwd points at the project root that contains components.json.","Check file read permissions on the cwd."],"exampleFix":"# before\nshadcn add button   # in a dir with no components.json, init skipped\n\n# after\nshadcn init\nshadcn add button","handlingStrategy":"validation","validationCode":"import { existsSync } from \"node:fs\"\nimport { join } from \"node:path\"\nconst cfgPath = join(options.cwd, \"components.json\")\nif (!existsSync(cfgPath)) {\n  // run `shadcn init` or surface a clear error before calling add\n}","typeGuard":"import { existsSync } from \"node:fs\"\nimport { join } from \"node:path\"\nconst hasComponentsJson = (cwd: string): boolean =>\n  existsSync(join(cwd, \"components.json\"))","tryCatchPattern":"try {\n  await addHandler(options)\n} catch (e) {\n  if (/Failed to read config/.test((e as Error).message)) {\n    // prompt to run init, then retry\n  } else throw e\n}","preventionTips":["Always run `shadcn init` before `shadcn add` in fresh projects.","Verify cwd contains components.json in CI scripts.","Check file read permissions on the project directory."],"tags":["cli","config","shadcn","filesystem"],"backgroundTag":null,"analyzedSha":"efac5987074af84ece57c367c6dd83387b967022","analyzedAt":"2026-08-12T05:00:50.218Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}