{"record":{"id":"346db42015b0852c","repo":"shadcn-ui/ui","slug":"failed-to-load-config-tsx-tsconfig-jsconf","errorCode":null,"errorMessage":"Failed to load ${config.tsx ? \"tsconfig\" : \"jsconfig\"}.json. ${tsConfig.message ?? \"\"}","messagePattern":"Failed to load (.+?)\\.json\\. (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/shadcn/src/utils/get-config.ts","lineNumber":61,"sourceCode":"\n  return await resolveConfigPaths(cwd, config)\n}\n\nexport async function resolveConfigPaths(\n  cwd: string,\n  config: z.infer<typeof rawConfigSchema>\n) {\n  // Merge built-in registries with user registries\n  config.registries = {\n    ...BUILTIN_REGISTRIES,\n    ...(config.registries || {}),\n  }\n\n  // Read tsconfig.json.\n  const tsConfig = await loadConfig(cwd)\n\n  if (tsConfig.resultType === \"failed\") {\n    throw new Error(\n      `Failed to load ${config.tsx ? \"tsconfig\" : \"jsconfig\"}.json. ${\n        tsConfig.message ?? \"\"\n      }`.trim()\n    )\n  }\n\n  // Resolve the primary aliases first so fallbacks can reuse their results.\n  const resolvedUtils = await resolveAliasPath(\n    \"utils\",\n    config.aliases[\"utils\"],\n    cwd,\n    tsConfig\n  )\n  const resolvedComponents = await resolveAliasPath(\n    \"components\",\n    config.aliases[\"components\"],\n    cwd,\n    tsConfig","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/shadcn-ui/ui/blob/efac5987074af84ece57c367c6dd83387b967022/packages/shadcn/src/utils/get-config.ts#L43-L79","documentation":"Thrown by resolveConfigPaths when the tsconfig/jsconfig loader (loadConfig from tsconfig-paths) reports resultType === \"failed\". shadcn needs the TS/JS config to resolve path aliases, so a failed load aborts config resolution. The message includes the loader's own message when present.","triggerScenarios":"During getConfig/resolveConfigPaths, loadConfig(cwd) returns { resultType: 'failed', message }. This happens when tsconfig.json (or jsconfig.json when config.tsx is false) is missing, unreadable, malformed JSON, or references extends paths that cannot be resolved.","commonSituations":"Running shadcn in a directory without a tsconfig.json; tsconfig.json with a syntax/JSON error; an \"extends\" pointing at a non-existent package; corrupt jsconfig.json in a non-TSX project; running from the wrong directory.","solutions":["Ensure a valid tsconfig.json (or jsconfig.json for JS projects) exists at the cwd shown in the message.","Open the config and fix any JSON syntax errors; validate with `npx tsc --noEmit` or a JSON linter.","Check every \"extends\" target resolves (install missing packages or correct the path).","Re-run `npx shadcn@latest init` if the project config is unrecoverable."],"exampleFix":"// tsconfig.json (before) — trailing comma / broken JSON\n{\n  \"compilerOptions\": { \"paths\": { \"@/*\": [\"./src/*\"] } },\n}\n// after\n{\n  \"compilerOptions\": { \"paths\": { \"@/*\": [\"./src/*\"] } }\n}","handlingStrategy":"validation","validationCode":"import { loadConfig } from \"tsconfig-paths\"\nconst tsConfig = await loadConfig(cwd)\nif (tsConfig.resultType === \"failed\") {\n  throw new Error(`tsconfig load failed: ${tsConfig.message ?? \"unknown\"}`)\n}","typeGuard":"const isTsConfigOk = (c: any) => c.resultType === \"success\"","tryCatchPattern":"try {\n  await getConfig(cwd)\n} catch (e) {\n  if (e instanceof Error && /Failed to load (ts|js)config/.test(e.message)) {\n    // guide user to fix tsconfig.json\n  }\n  throw e\n}","preventionTips":["Always commit a valid tsconfig.json/jsconfig.json at the project root.","Validate tsconfig with `npx tsc --noEmit` before running shadcn.","Ensure every \"extends\" target is installed.","Run shadcn from the directory containing the tsconfig."],"tags":["config","typescript","tsconfig","init"],"backgroundTag":null,"analyzedSha":"efac5987074af84ece57c367c6dd83387b967022","analyzedAt":"2026-08-12T05:00:50.218Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:31:55.035Z"}