shadcn-ui/ui · error · Error

Could not load the workspace config in ${highlighter.info(pa

Error message

Could not load the workspace config in ${highlighter.info(packageRoot)}.
Add ${highlighter.info("components.json")} to this workspace and configure its path aliases or package imports, then try again.

What it means

Thrown by getWorkspaceConfig when, for a resolved alias, findPackageRoot locates a package root but getConfig(packageRoot) returns no components.json config. In a monorepo, shadcn expects each package root that aliases point into to have its own components.json defining path aliases/imports.

Source

Thrown at packages/shadcn/src/utils/get-config.ts:254

    if (!isAliasKey(key, config)) {
      continue
    }

    const resolvedPath = config.resolvedPaths[key]
    const packageRoot = await findPackageRoot(
      config.resolvedPaths.cwd,
      resolvedPath
    )

    if (!packageRoot) {
      resolvedAliases[key] = config
      continue
    }

    const workspaceConfig = await getConfig(packageRoot)

    if (!workspaceConfig) {
      throw new Error(
        [
          `Could not load the workspace config in ${highlighter.info(packageRoot)}.`,
          `Add ${highlighter.info(
            "components.json"
          )} to this workspace and configure its path aliases or package imports, then try again.`,
        ].join("\n")
      )
    }

    resolvedAliases[key] = workspaceConfig
  }

  const result = workspaceConfigSchema.safeParse(resolvedAliases)
  if (!result.success) {
    return null
  }

  return result.data

View on GitHub (pinned to efac598707)

Solutions

  1. Create a components.json in the package root named in the message.
  2. In that components.json, configure the path aliases or package imports so the aliases resolve within that package.
  3. Re-run the command; if multiple packages are flagged, repeat for each.
  4. Alternatively, ensure the alias resolves within the root package so findPackageRoot returns null (skipping the workspace-config branch).

Example fix

# before — packages/ui has no components.json
# after — create packages/ui/components.json
{
  "$schema": "https://ui.shadcn.com/schema.json",
  "style": "new-york",
  "rsc": true,
  "tsx": true,
  "tailwind": { "config": "", "css": "styles/globals.css", "baseColor": "neutral" },
  "aliases": { "components": "@/components", "utils": "@/lib/utils", "ui": "@/components/ui", "lib": "@/lib", "hooks": "@/hooks" },
  "iconLibrary": "lucide"
}
Defensive patterns

Strategy: validation

Validate before calling

import fsExtra from "fs-extra"
async function hasComponentsJson(pkgRoot: string): Promise<boolean> {
  return fsExtra.pathExists(`${pkgRoot}/components.json`)
}
for (const key of Object.keys(config.aliases)) {
  const root = await findPackageRoot(config.resolvedPaths.cwd, config.resolvedPaths[key])
  if (root && !(await hasComponentsJson(root))) {
    throw new Error(`missing components.json in ${root}`)
  }
}

Type guard

const workspaceConfigExists = async (pkgRoot: string) =>
  fsExtra.pathExists(`${pkgRoot}/components.json`)

Try / catch

try {
  await getWorkspaceConfig(config)
} catch (e) {
  if (e instanceof Error && /Could not load the workspace config/.test(e.message)) {
    // create components.json in the flagged packageRoot
  }
  throw e
}

Prevention

When it happens

Trigger: getWorkspaceConfig iterates alias keys; for each, findPackageRoot(config.cwd, resolvedPath) finds a package.json root; getConfig(packageRoot) returns null (no components.json there); the error fires for the first such package.

Common situations: Monorepo (pnpm/npm workspaces) where ui alias resolves into a workspace package that lacks components.json; partial monorepo setup where only the root has config; alias pointing at an external package root.

Related errors


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