shadcn-ui/ui · error · Error

No `components.json` file found. Ensure you are at the root…

Error message

No `components.json` file found. Ensure you are at the root of your project.

What it means

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`.

Solutions

  1. Run `shadcn init` first to create components.json.
  2. cd to the project root that contains components.json.
  3. Verify the file exists: `ls components.json`.
Defensive patterns

Strategy: validation

Validate before calling

import fs from "fs"
import path from "path"

function assertHasComponentsJson(cwd: string) {
  if (!fs.existsSync(path.resolve(cwd, "components.json"))) {
    throw new Error("Run `shadcn init` before `shadcn migrate`.")
  }
}

Prevention

When it happens

Trigger: 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.

Common situations: Wrong terminal cwd (home dir, subdirectory), fresh repo that was never initialized, components.json deleted or never committed, monorepo run from the wrong package.

Related errors


AI-assisted analysis of shadcn-ui/ui@5c7072da67 (2026-09-07). Data as JSON: /api/errors/e323b388f76ac15a. Report an issue: GitHub.

Appendix: source

Thrown at packages/shadcn/src/commands/migrate.ts:106

        for (const migration of migrations) {
          logger.info(`- ${migration.name}: ${migration.description}`)
        }
        return
      }

      if (options.migration === "cn") {
        await migrateCn({
          cwd: options.cwd,
          path: options.path,
          yes: options.yes,
        })
        return
      }

      const { errors, config } = await preFlightMigrate(options)

      if (errors[ERRORS.MISSING_DIR_OR_EMPTY_PROJECT]) {
        throw new Error(
          "No `components.json` file found. Ensure you are at the root of your project."
        )
      }

      if (errors[ERRORS.MISSING_CONFIG]) {
        throw new Error(
          "No `components.json` file found. Ensure you are at the root of your project."
        )
      }

      if (!config) {
        throw new Error(
          "Something went wrong reading your `components.json` file. Please ensure you have a valid `components.json` file."
        )
      }

      if (options.migration === "icons") {
        await migrateIcons(config, {

View on GitHub (pinned to 5c7072da67)