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.dataView on GitHub (pinned to efac598707)
Solutions
- Create a components.json in the package root named in the message.
- In that components.json, configure the path aliases or package imports so the aliases resolve within that package.
- Re-run the command; if multiple packages are flagged, repeat for each.
- 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
- In monorepos, add components.json to every package whose path an alias resolves into.
- Keep each package's components.json aliases self-contained.
- Run init inside each workspace package to scaffold configs.
- Verify alias roots point within a package that has its own config.
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
- No `components.json` file found. Ensure you are at the root
- No components.json found. Run shadcn init first.
- Failed to load ${config.tsx ? "tsconfig" : "jsconfig"}.json.
- Could not resolve the following aliases in ${highlighter.inf
- "${registryName}" is a built-in registry and cannot be overr
AI-assisted analysis of shadcn-ui/ui@efac598707 (2026-08-12).
Data as JSON: /api/errors/33b6f92369bb8c5d.
Report an issue: GitHub.