shadcn-ui/ui · error

No components.json found. Run shadcn init first.

Error message

No components.json found. Run shadcn init first.

What it means

addRegistriesToConfig requires an existing components.json in the cwd; without it there is nowhere to record the registry entry. Thrown before any network call is made.

Source

Thrown at packages/shadcn/src/commands/registry/add.ts:80

        `Registry names must start with @ (e.g., @acme).`
    )
  }

  return { namespace, url }
}

function pluralize(count: number, singular: string, plural: string) {
  return `${count} ${count === 1 ? singular : plural}`
}

async function addRegistriesToConfig(
  registryArgs: string[],
  cwd: string,
  options: { silent?: boolean }
) {
  const configPath = path.resolve(cwd, "components.json")
  if (!fs.existsSync(configPath)) {
    throw new Error(
      `No ${highlighter.info("components.json")} found. Run ${highlighter.info(
        "shadcn init"
      )} first.`
    )
  }

  const parsed = registryArgs.map(parseRegistryArg)
  const needsLookup = parsed.filter((p) => !p.url)
  let registriesIndex: { name: string; url: string }[] = []
  if (needsLookup.length > 0) {
    const fetchSpinner = spinner("Fetching registries.", {
      silent: options.silent,
    }).start()
    const registries = await getRegistries()
    if (!registries) {
      fetchSpinner.fail()
      throw new Error("Failed to fetch registries.")
    }

View on GitHub (pinned to efac598707)

Solutions

  1. Run `shadcn init` first.
  2. Confirm you are in the project root: `ls components.json`.
  3. Recreate components.json via init or restore it from git.
Defensive patterns

Strategy: validation

Validate before calling

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

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

Prevention

When it happens

Trigger: Running `shadcn registry add ...` in a directory that was never initialized with `shadcn init` (no components.json present at cwd).

Common situations: Wrong cwd, fresh project not yet initialized, components.json deleted or removed via git.

Related errors


AI-assisted analysis of shadcn-ui/ui@efac598707 (2026-08-12). Data as JSON: /api/errors/9ff6520c61ece5fd. Report an issue: GitHub.