{"record":{"id":"b1fa11ef6370a6a7","repo":"angular/angular-cli","slug":"workspace-schema-is-not-a-json-object","errorCode":null,"errorMessage":"Workspace schema is not a JSON object.","messagePattern":"Workspace schema is not a JSON object\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/angular/cli/src/utilities/config.ts","lineNumber":243,"sourceCode":"  if (!configPath) {\n    if (level === 'global') {\n      configPath = defaultGlobalFilePath;\n      // Config doesn't exist, force create it.\n\n      const globalWorkspace = await getWorkspace('global');\n      await globalWorkspace.save();\n    } else {\n      return [null, null];\n    }\n  }\n\n  return [new JSONFile(configPath), configPath];\n}\n\nexport async function validateWorkspace(data: json.JsonObject, isGlobal: boolean): Promise<void> {\n  const schema = readAndParseJson(workspaceSchemaPath);\n  if (!isJsonObject(schema)) {\n    throw new Error('Workspace schema is not a JSON object.');\n  }\n\n  // We should eventually have a dedicated global config schema and use that to validate.\n  const schemaToValidate: json.schema.JsonSchema = isGlobal\n    ? {\n        '$ref': '#/definitions/global',\n        definitions: schema['definitions'] as json.JsonObject,\n      }\n    : schema;\n\n  const { formats } = await import('@angular-devkit/schematics');\n  const registry = new json.schema.CoreSchemaRegistry(formats.standardFormats);\n  const validator = await registry.compile(schemaToValidate);\n  const { success, errors } = await validator(data);\n  if (!success) {\n    throw new json.schema.SchemaValidationException(errors);\n  }\n}","sourceCodeStart":225,"sourceCodeEnd":261,"githubUrl":"https://github.com/angular/angular-cli/blob/bb72145f9ab45aee29f523236b3a25cd0813a841/packages/angular/cli/src/utilities/config.ts#L225-L261","documentation":"`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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before (patched schema file contains a string)\n\"@angular/cli\": \"11.0.0-next.6\"  // corrupted local install\n// after\nrm -rf node_modules package-lock.json && npm install\n\"@angular/cli\": \"^11.0.0\"","handlingStrategy":"try-catch","validationCode":"import { readFileSync } from 'node:fs';\nconst schema = JSON.parse(readFileSync('node_modules/@angular/cli/lib/config/workspace-schema.json', 'utf8'));\nif (typeof schema !== 'object' || schema === null || Array.isArray(schema)) {\n  throw new Error('Workspace schema asset is corrupt; reinstall @angular/cli.');\n}","typeGuard":"function isJsonObject(v: unknown): v is Record<string, unknown> {\n  return typeof v === 'object' && v !== null && !Array.isArray(v);\n}","tryCatchPattern":"try {\n  await ngConfigSet('cli.analytics', false);\n} catch (e) {\n  if (e instanceof Error && e.message === 'Workspace schema is not a JSON object.') {\n    // reinstall/repair @angular/cli installation\n  } else { throw e; }\n}","preventionTips":["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."],"tags":["config","schema","angular-cli","internal"],"backgroundTag":"schema-validation-failed","analyzedSha":"bb72145f9ab45aee29f523236b3a25cd0813a841","analyzedAt":"2026-08-30T02:47:34.745Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}