{"record":{"id":"1672103caaa26cf4","repo":"angular/angular-cli","slug":"unable-to-read-workspace-file","errorCode":null,"errorMessage":"Unable to read workspace file.","messagePattern":"Unable to read workspace file\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/angular_devkit/core/src/workspace/json/reader.ts","lineNumber":48,"sourceCode":"  readonly unprefixedWorkspaceExtensions: ReadonlySet<string>;\n  readonly unprefixedProjectExtensions: ReadonlySet<string>;\n  error(message: string, node: JsonValue): void;\n  warn(message: string, node: JsonValue): void;\n}\n\nexport interface JsonWorkspaceOptions {\n  allowedProjectExtensions?: string[];\n  allowedWorkspaceExtensions?: string[];\n}\n\nexport async function readJsonWorkspace(\n  path: string,\n  host: WorkspaceHost,\n  options: JsonWorkspaceOptions = {},\n): Promise<WorkspaceDefinition> {\n  const raw = await host.readFile(path);\n  if (raw === undefined) {\n    throw new Error('Unable to read workspace file.');\n  }\n\n  const ast = parseTree(raw, undefined, { allowTrailingComma: true, disallowComments: false });\n  if (ast?.type !== 'object' || !ast.children) {\n    throw new Error('Invalid workspace file - expected JSON object.');\n  }\n\n  // Version check\n  const versionNode = findNodeAtLocation(ast, ['version']);\n  if (!versionNode) {\n    throw new Error('Unknown format - version specifier not found.');\n  }\n  const version = versionNode.value;\n  if (version !== 1) {\n    throw new Error(`Invalid format version detected - Expected:[ 1 ] Found: [ ${version} ]`);\n  }\n\n  const context: ParserContext = {","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/angular/angular-cli/blob/bb72145f9ab45aee29f523236b3a25cd0813a841/packages/angular_devkit/core/src/workspace/json/reader.ts#L30-L66","documentation":"readJsonWorkspace reads the file via host.readFile(path); if the host returns undefined (file missing/unreadable) it throws 'Unable to read workspace file.' It is the reader's hard failure for an inaccessible workspace file, before any JSON parsing occurs.","triggerScenarios":"Calling readWorkspace('angular.json', host) when angular.json does not exist at that path, the path is wrong, or the custom WorkspaceHost's readFile returns undefined (e.g. virtual fs without the file registered).","commonSituations":"Running schematics/tools outside an Angular workspace directory; typo'd filename (angular.json vs workspace.json); file deleted or not committed; custom host pointing at the wrong root.","solutions":["Verify the workspace file exists at the given path and the process CWD/root is correct.","Ensure the WorkspaceHost (e.g. createWorkspaceHost / virtual fs) is rooted where the file lives.","Create the workspace file (ng new / workspace config) before reading.","Catch this error and prompt the user for a valid workspace path."],"exampleFix":"// before\nconst ws = await readWorkspace('angluar.json', host); // typo\n// after\nconst ws = await readWorkspace('angular.json', host);","handlingStrategy":"validation","validationCode":"import { existsSync } from 'fs';\nif (!existsSync(workspacePath)) {\n  throw new Error(`No workspace file at ${workspacePath}; run inside an Angular workspace`);\n}\nconst ws = await readWorkspace(workspacePath, host);","typeGuard":"function workspaceFileExists(path: string, host: WorkspaceHost): Promise<boolean> {\n  return host.readFile(path).then(raw => raw !== undefined);\n}","tryCatchPattern":"try {\n  const ws = await readWorkspace('angular.json', host);\n} catch (e) {\n  if (e.message === 'Unable to read workspace file.') {\n    console.error('No angular.json found; run `ng new` or cd into the workspace root.');\n    process.exitCode = 1;\n  } else throw e;\n}","preventionTips":["Resolve the workspace path upward from CWD before reading (like ng does)","Verify the custom WorkspaceHost is rooted at the directory containing angular.json","Check for filename typos (angular.json vs workspace.json vs angluar.json)"],"tags":["workspace","file-not-found","io","angular-devkit"],"backgroundTag":"file-not-found","analyzedSha":"bb72145f9ab45aee29f523236b3a25cd0813a841","analyzedAt":"2026-08-30T02:47:34.745Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}