{"record":{"id":"e323b388f76ac15a","repo":"shadcn-ui/ui","slug":"no-components-json-file-found-ensure-you-are-at","errorCode":null,"errorMessage":"No `components.json` file found. Ensure you are at the root of your project.","messagePattern":"No `components\\.json` file found\\. Ensure you are at the root of your project\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/shadcn/src/commands/migrate.ts","lineNumber":106,"sourceCode":"        for (const migration of migrations) {\n          logger.info(`- ${migration.name}: ${migration.description}`)\n        }\n        return\n      }\n\n      if (options.migration === \"cn\") {\n        await migrateCn({\n          cwd: options.cwd,\n          path: options.path,\n          yes: options.yes,\n        })\n        return\n      }\n\n      const { errors, config } = await preFlightMigrate(options)\n\n      if (errors[ERRORS.MISSING_DIR_OR_EMPTY_PROJECT]) {\n        throw new Error(\n          \"No `components.json` file found. Ensure you are at the root of your project.\"\n        )\n      }\n\n      if (errors[ERRORS.MISSING_CONFIG]) {\n        throw new Error(\n          \"No `components.json` file found. Ensure you are at the root of your project.\"\n        )\n      }\n\n      if (!config) {\n        throw new Error(\n          \"Something went wrong reading your `components.json` file. Please ensure you have a valid `components.json` file.\"\n        )\n      }\n\n      if (options.migration === \"icons\") {\n        await migrateIcons(config, {","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/shadcn-ui/ui/blob/5c7072da672b0048bc6771e3204063a2537df91a/packages/shadcn/src/commands/migrate.ts#L88-L124","documentation":"This is the shadcn CLI's `migrate` command aborting during its pre-flight check before running any migration. `preFlightMigrate(options)` runs validation steps (ensuring the working directory exists and is not empty, and loading `components.json`) and returns a flag map of sentinel errors instead of throwing. This throw fires when the flag keyed by ERRORS.MISSING_DIR_OR_EMPTY_PROJECT is set, meaning the resolved cwd is missing or an empty project — not that `components.json` alone is absent (a separate MISSING_CONFIG flag covers a present project with no config file). The CLI wraps both cases in the same user-facing message because running from the project root with a valid `components.json` resolves both. It is a plain Error thrown deliberately to stop the command; callers should run the CLI from a project root containing `components.json`.","triggerScenarios":"Running `shadcn migrate <name>` from a directory without components.json, or from an empty/brand-new directory; preFlightMigrate could not locate or validate a project config.","commonSituations":"Wrong terminal cwd (home dir, subdirectory), fresh repo that was never initialized, components.json deleted or never committed, monorepo run from the wrong package.","solutions":["Run `shadcn init` first to create components.json.","cd to the project root that contains components.json.","Verify the file exists: `ls components.json`."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"import fs from \"fs\"\nimport path from \"path\"\n\nfunction assertHasComponentsJson(cwd: string) {\n  if (!fs.existsSync(path.resolve(cwd, \"components.json\"))) {\n    throw new Error(\"Run `shadcn init` before `shadcn migrate`.\")\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run migrate only after a successful shadcn init.","Confirm cwd is the project root before invoking."],"tags":["migrate","config","init"],"backgroundTag":null,"analyzedSha":"5c7072da672b0048bc6771e3204063a2537df91a","analyzedAt":"2026-09-07T00:08:47.579Z","contentChangedAt":"2026-09-07T00:08:47.579Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}