shadcn-ui/ui · error · Error

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

Error message

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

What it means

migrateCn is a project-level migration and needs a package.json at the working directory to locate dependencies and run package-manager commands. Before doing anything it checks fsExtra.existsSync(cwd/package.json) and throws this error if absent, telling you to run from the project root.

Solutions

  1. cd into the directory containing package.json (project or app root) and rerun the migration.
  2. In a monorepo, run from the workspace app that has the dependencies, or set cwd explicitly to that app.
  3. If package.json is missing because the project was never initialized, run `npm init -y` (or your package manager's init) first.

Example fix

// before
await migrateCn({ cwd: '/repo/packages/app/src' })
// after
await migrateCn({ cwd: '/repo/packages/app' })
Defensive patterns

Strategy: validation

Validate before calling

import { existsSync } from 'fs'
import { resolve } from 'path'
if (!existsSync(resolve(process.cwd(), 'package.json'))) {
  throw new Error('Run from the project root containing package.json')
}
await migrateCn({ cwd: process.cwd() })

Prevention

When it happens

Trigger: Running `shadcn migrate cn` (or migrateCn) with cwd set to a directory containing no package.json — a subdirectory like src/, a parent directory, a temp folder, or an empty repo.

Common situations: Running the CLI from a monorepo root whose workspace apps live in subdirectories (or vice versa, running inside packages/app when the CLI expects the root), running in a freshly cloned repo before `npm install` generated nothing relevant, or in a non-Node project.

Related errors


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

Appendix: source

Thrown at packages/shadcn/src/migrations/cn/index.ts:27

  removeDependencies,
} from "@/src/utils/updaters/update-dependencies"
import fsExtra from "fs-extra"
import prompts from "prompts"

import { resolveMigrationFiles } from "./files"
import { createCnTransformer } from "./transform"
import { OLD_PACKAGES, type CnMigrationIssue, type OldPackage } from "./types"

export { transformCnSource } from "./transform"
export type { CnMigrationIssue, CnSourceTransformResult } from "./types"

export async function migrateCn(options: {
  cwd: string
  path?: string
  yes?: boolean
}) {
  if (!fsExtra.existsSync(path.resolve(options.cwd, "package.json"))) {
    throw new Error(
      "No `package.json` file found. Ensure you are at the root of your project."
    )
  }

  const files = await resolveMigrationFiles(options.cwd, options.path)
  const contents = await Promise.all(
    files.map((file) => fs.readFile(file, "utf-8"))
  )
  const transform = createCnTransformer()
  const results = files.map((file, index) => {
    const content = contents[index]
    return { file, content, result: transform(content, file) }
  })

  const changedFiles = results.filter(
    ({ content, result }) => content !== result.content
  )
  const unsupported = results.flatMap(({ file, result }) =>

View on GitHub (pinned to 5c7072da67)