shadcn-ui/ui · error · Error

No ${highlighter.info("components.json")} or ${highlighter.i

Error message

No ${highlighter.info("components.json")} or ${highlighter.info("package.json")} found. Run ${highlighter.info("shadcn init")} first.

What it means

Thrown by addRegistriesToConfig, the function behind `shadcn registry add`. The command persists registered registries into either components.json or package.json, and it locates them by checking fs.existsSync on both files in the target cwd. If neither file exists there, there is nowhere to write the registry entry, so the CLI aborts and tells you to run `shadcn init` first.

Source

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

}

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

export async function addRegistriesToConfig(
  registryArgs: string[],
  cwd: string,
  options: { silent?: boolean }
) {
  // Write to components.json when it exists, otherwise fall back to
  // package.json. This mirrors how registries are resolved.
  const configPath = ["components.json", "package.json"]
    .map((file) => path.resolve(cwd, file))
    .find((file) => fs.existsSync(file))

  if (!configPath) {
    throw new Error(
      `No ${highlighter.info("components.json")} or ${highlighter.info(
        "package.json"
      )} found. Run ${highlighter.info("shadcn init")} first.`
    )
  }

  const configFileName = path.basename(configPath)

  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()

View on GitHub (pinned to c06da1d0e9)

Solutions

  1. Run the command from a directory that already has a package.json (usually the project root), or pass the correct path: `npx shadcn@latest registry add -c path/to/project @acme=...`.
  2. If the project was never initialized, run `npx shadcn@latest init` first to create components.json, then retry the registry add.
  3. In a non-Node directory, create a minimal package.json (name + version) so the CLI has a place to record the `registries` field.

Example fix

// before (run in an empty directory)
npx shadcn@latest registry add @acme=https://acme.com/r/{name}.json
// -> No components.json or package.json found. Run shadcn init first.

// after
cd my-app                          # directory containing package.json
npx shadcn@latest init             # only if components.json does not exist yet
npx shadcn@latest registry add @acme=https://acme.com/r/{name}.json
Defensive patterns

Strategy: validation

Validate before calling

import { existsSync } from 'fs'
import path from 'path'

// Run before invoking `shadcn registry add` or addRegistriesToConfig().
function canAddRegistries(cwd: string): boolean {
  return (
    existsSync(path.resolve(cwd, 'components.json')) ||
    existsSync(path.resolve(cwd, 'package.json'))
  )
}

if (!canAddRegistries(process.cwd())) {
  console.error('Initialize the project first: npx shadcn@latest init')
  process.exit(1)
}

Prevention

When it happens

Trigger: Running `npx shadcn@latest registry add @acme=https://example.com/r/{name}.json` in a directory that contains neither components.json nor package.json — e.g. an empty folder, a non-Node project root, a random subdirectory, or passing `-c/--cwd` that points at the wrong path. Also hit when calling the exported addRegistriesToConfig(registryArgs, cwd) programmatically with a cwd that has no config file.

Common situations: Running the command from a fresh directory before ever running `shadcn init`; running it one level off the project root in a monorepo; a typo in --cwd; CI or tooling invoking the API against a scratch directory.

Related errors


AI-assisted analysis of shadcn-ui/ui@c06da1d0e9 (2026-08-21). Data as JSON: /api/errors/066cf92d68d28cf0. Report an issue: GitHub.