angular/angular-cli · error · Error
Workspace schema is not a JSON object.
Error message
Workspace schema is not a JSON object.
What it means
`validateWorkspace` reads the workspace JSON schema bundled with the CLI (`workspaceSchemaPath`) and, before using it as a validation schema, checks that the parsed schema itself is a JSON object. If the schema file is not an object, the CLI cannot validate workspace data and throws this internal-consistency error. It almost always indicates a corrupted or wrong-version CLI installation.
Source
Thrown at packages/angular/cli/src/utilities/config.ts:243
if (!configPath) {
if (level === 'global') {
configPath = defaultGlobalFilePath;
// Config doesn't exist, force create it.
const globalWorkspace = await getWorkspace('global');
await globalWorkspace.save();
} else {
return [null, null];
}
}
return [new JSONFile(configPath), configPath];
}
export async function validateWorkspace(data: json.JsonObject, isGlobal: boolean): Promise<void> {
const schema = readAndParseJson(workspaceSchemaPath);
if (!isJsonObject(schema)) {
throw new Error('Workspace schema is not a JSON object.');
}
// We should eventually have a dedicated global config schema and use that to validate.
const schemaToValidate: json.schema.JsonSchema = isGlobal
? {
'$ref': '#/definitions/global',
definitions: schema['definitions'] as json.JsonObject,
}
: schema;
const { formats } = await import('@angular-devkit/schematics');
const registry = new json.schema.CoreSchemaRegistry(formats.standardFormats);
const validator = await registry.compile(schemaToValidate);
const { success, errors } = await validator(data);
if (!success) {
throw new json.schema.SchemaValidationException(errors);
}
}View on GitHub (pinned to bb72145f9a)
Solutions
- Reinstall the CLI cleanly: `rm -rf node_modules package-lock.json && npm install`.
- Verify the schema file exists and is valid JSON at `node_modules/@angular/cli/lib/config/workspace-schema.json` (or equivalent).
- Check for bundler/path patches (patch-package, module aliases) that redirect the schema file.
- Pin/upgrade `@angular/cli` to a release where the schema asset is intact.
Example fix
// before (patched schema file contains a string) "@angular/cli": "11.0.0-next.6" // corrupted local install // after rm -rf node_modules package-lock.json && npm install "@angular/cli": "^11.0.0"
Defensive patterns
Strategy: try-catch
Validate before calling
import { readFileSync } from 'node:fs';
const schema = JSON.parse(readFileSync('node_modules/@angular/cli/lib/config/workspace-schema.json', 'utf8'));
if (typeof schema !== 'object' || schema === null || Array.isArray(schema)) {
throw new Error('Workspace schema asset is corrupt; reinstall @angular/cli.');
} Type guard
function isJsonObject(v: unknown): v is Record<string, unknown> {
return typeof v === 'object' && v !== null && !Array.isArray(v);
} Try / catch
try {
await ngConfigSet('cli.analytics', false);
} catch (e) {
if (e instanceof Error && e.message === 'Workspace schema is not a JSON object.') {
// reinstall/repair @angular/cli installation
} else { throw e; }
} Prevention
- Reinstall node_modules cleanly after CLI upgrades or patching.
- Do not redirect/alias the workspace schema file in bundlers or patch-package.
- Verify installed CLI integrity (npm ls @angular/cli, npm audit/integrity checks).
- Pin a known-good @angular/cli version in package.json.
When it happens
Trigger: Calling config APIs that run `validateWorkspace` (e.g. `config.set`) when the parsed schema file at `workspaceSchemaPath` is not a `JsonObject` — e.g. the schema file resolved to HTML (404 page), an error string, or is empty.
Common situations: Broken or partially installed `@angular/cli` node_modules; a bundler/resolver aliasing the schema path to the wrong file; patched CLI builds where the schema asset was replaced; symlinked/hoisted node_modules conflicts.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- Could not find ${level} workspace.
- Invalid config found at ${workspace.filePath}. CLI should be
- Cannot retrieve cache configuration as workspace is not defi
- Invalid Path.
- Confguration file cannot be found.
AI-assisted analysis of angular/angular-cli@bb72145f9a (2026-08-30).
Data as JSON: /api/errors/b1fa11ef6370a6a7.
Report an issue: GitHub.