{"record":{"id":"03c84a8a11e1ec21","repo":"angular/angular-cli","slug":"cannot-retrieve-cache-configuration-as-workspace-i","errorCode":null,"errorMessage":"Cannot retrieve cache configuration as workspace is not defined.","messagePattern":"Cannot retrieve cache configuration as workspace is not defined\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/angular/cli/src/commands/cache/utilities.ts","lineNumber":69,"sourceCode":"              return resolve(dirname(commonGitDir), cachePathSetting);\n            }\n          }\n        }\n      }\n      const parentDir = dirname(currentDir);\n      if (parentDir === currentDir) {\n        break;\n      }\n      currentDir = parentDir;\n    }\n  } catch {}\n\n  return resolve(workspaceRoot, cachePathSetting);\n}\n\nexport function getCacheConfig(workspace: AngularWorkspace | undefined): Required<Cache> {\n  if (!workspace) {\n    throw new Error(`Cannot retrieve cache configuration as workspace is not defined.`);\n  }\n\n  const defaultSettings: Required<Cache> = {\n    path: getCacheBasePath(workspace.basePath, '.angular/cache'),\n    environment: Environment.Local,\n    enabled: true,\n  };\n\n  const cliSetting = workspace.extensions['cli'];\n  if (!cliSetting || !isJsonObject(cliSetting)) {\n    return defaultSettings;\n  }\n\n  const cacheSettings = cliSetting['cache'];\n  if (!isJsonObject(cacheSettings)) {\n    return defaultSettings;\n  }\n","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/angular/angular-cli/blob/bb72145f9ab45aee29f523236b3a25cd0813a841/packages/angular/cli/src/commands/cache/utilities.ts#L51-L87","documentation":"getCacheConfig() in the Angular CLI's cache command utilities returns the effective cache settings (path, environment, enabled) for a workspace. Because the entire function is meaningless without a workspace, it explicitly throws a plain Error when the passed AngularWorkspace is undefined instead of silently returning defaults.","triggerScenarios":"Calling getCacheConfig(undefined) — typically from command handlers (e.g. `ng cache clean`, `ng cache enable`) executed in a context where the workspace file (angular.json) could not be located, so the resolved workspace is undefined before being passed in.","commonSituations":"Running `ng cache` commands outside an Angular workspace directory (no angular.json in or above cwd); a corrupted or renamed angular.json; invoking the cache utilities programmatically without first resolving a workspace.","solutions":["Run the command from inside an Angular project directory (angular.json present in cwd or an ancestor)","Restore/rename angular.json if it was deleted or renamed","If calling the API programmatically, resolve the workspace first with getWorkspace/getWorkspaceRaw and pass the result to getCacheConfig","Check that cli.workspaceContext / workspace root detection is correctly configured if embedding the CLI"],"exampleFix":"// before\nconst config = getCacheConfig(undefined);\n// after\nconst workspace = await getWorkspace('local');\nif (!workspace) {\n  throw new Error('Run this command inside an Angular workspace (angular.json not found).');\n}\nconst config = getCacheConfig(workspace);","handlingStrategy":"validation","validationCode":"import { getWorkspace } from '@angular/cli/src/utilities/workspace';\nconst workspace = await getWorkspace('local');\nif (!workspace) {\n  throw new Error('No Angular workspace found; `ng cache` requires angular.json.');\n}\nconst cacheConfig = getCacheConfig(workspace);","typeGuard":"function hasWorkspace(w: AngularWorkspace | undefined | null): w is AngularWorkspace {\n  return !!w && typeof w.basePath === 'string';\n}","tryCatchPattern":"try {\n  const config = getCacheConfig(maybeWorkspace);\n} catch (e) {\n  if (e instanceof Error && e.message.includes('workspace is not defined')) {\n    logger.error('Run this command inside an Angular workspace (angular.json missing).');\n  } else { throw e; }\n}","preventionTips":["Always resolve the workspace before calling cache utilities","Run cache commands from the project root, not a parent/sibling directory","Verify angular.json exists in VCS and CI checkouts","Add a preflight check in scripts: test -f angular.json"],"tags":["angular-cli","cache","workspace","config"],"backgroundTag":"workspace-not-found","analyzedSha":"bb72145f9ab45aee29f523236b3a25cd0813a841","analyzedAt":"2026-08-30T02:47:34.745Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}