{"record":{"id":"342d8985d981861d","repo":"angular/angular-cli","slug":"could-not-find-level-workspace","errorCode":null,"errorMessage":"Could not find ${level} workspace.","messagePattern":"Could not find (.+?) workspace\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/angular/cli/src/analytics/analytics.ts","lineNumber":49,"sourceCode":"  return analyticsPackageSafelist.some((pattern) => {\n    if (typeof pattern == 'string') {\n      return pattern === name;\n    } else {\n      return pattern.test(name);\n    }\n  });\n}\n\n/**\n * Set analytics settings. This does not work if the user is not inside a project.\n * @param global Which config to use. \"global\" for user-level, and \"local\" for project-level.\n * @param value Either a user ID, true to generate a new User ID, or false to disable analytics.\n */\nexport async function setAnalyticsConfig(global: boolean, value: string | boolean): Promise<void> {\n  const level = global ? 'global' : 'local';\n  const workspace = await getWorkspace(level);\n  if (!workspace) {\n    throw new Error(`Could not find ${level} workspace.`);\n  }\n\n  const cli = (workspace.extensions['cli'] ??= {});\n  if (!workspace || !json.isJsonObject(cli)) {\n    throw new Error(`Invalid config found at ${workspace.filePath}. CLI should be an object.`);\n  }\n\n  cli.analytics = value === true ? randomUUID() : value;\n  await workspace.save();\n}\n\n/**\n * Prompt the user for usage gathering permission.\n * @param force Whether to ask regardless of whether or not the user is using an interactive shell.\n * @return Whether or not the user was shown a prompt.\n */\nexport async function promptAnalytics(\n  context: CommandContext,","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/angular/angular-cli/blob/bb72145f9ab45aee29f523236b3a25cd0813a841/packages/angular/cli/src/analytics/analytics.ts#L31-L67","documentation":"The Angular CLI's setAnalyticsConfig writes analytics settings into the 'cli' extensions of a workspace config file. Before writing, it resolves the workspace at the requested config level (global ~/.angular-config or local ./angular.json). If no config file exists at that level, it throws this error because there is nowhere to store the setting.","triggerScenarios":"Calling setAnalyticsConfig(true, ...) with no global config file, or setAnalyticsConfig(false, ...) while not inside an Angular project directory (no angular.json/.angular.json), e.g. via 'ng analytics' commands that persist settings.","commonSituations":"Running 'ng analytics disable' outside a project; running in a CI container where HOME points somewhere without a global Angular config; running from a subdirectory outside the workspace root.","solutions":["cd into the root of your Angular project before running analytics commands","Create the global config if needed: 'ng config --global cli.analytics false' or touch ~/.angular-config.json","Run from the directory containing angular.json, not a sibling folder","If using npm/npx, ensure the working directory is the workspace before invoking the CLI"],"exampleFix":"// before (run in ~/scripts, outside any project)\nng analytics disable\n// after\ncd ~/my-app && ng analytics disable","handlingStrategy":"validation","validationCode":"import { existsSync } from 'fs';\nimport { homedir } from 'os';\nimport { join } from 'path';\n\nfunction workspaceConfigExists(global: boolean): boolean {\n  return global\n    ? existsSync(join(homedir(), '.angular-config'))\n    : existsSync(join(process.cwd(), 'angular.json'));\n}\nif (!workspaceConfigExists(global)) {\n  // skip the call or create the config first\n}","typeGuard":null,"tryCatchPattern":"try {\n  await setAnalyticsConfig(global, value);\n} catch (e) {\n  if ((e as Error).message.includes('Could not find')) {\n    logger.warn(`No ${global ? 'global' : 'local'} workspace config; skipping analytics setting.`);\n  } else {\n    throw e;\n  }\n}","preventionTips":["Always run analytics/config commands from the workspace root","Set analytics globally (CI=true, NG_CLI_ANALYTICS=false) to avoid needing local config","Verify ~/.angular-config or angular.json exists before scripted CLI calls"],"tags":["angular-cli","workspace","config","analytics"],"backgroundTag":"workspace-not-found","analyzedSha":"bb72145f9ab45aee29f523236b3a25cd0813a841","analyzedAt":"2026-08-30T02:47:34.745Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}