{"record":{"id":"a17deaf6c9159a34","repo":"angular/angular-cli","slug":"could-not-find-a-level-workspace-are-you-in-a","errorCode":null,"errorMessage":"Could not find a ${level} workspace. Are you in a project?","messagePattern":"Could not find a (.+?) workspace\\. Are you in a project\\?","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/angular/cli/src/analytics/analytics.ts","lineNumber":74,"sourceCode":"\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,\n  global: boolean,\n  force = false,\n): Promise<boolean> {\n  const level = global ? 'global' : 'local';\n  const workspace = await getWorkspace(level);\n  if (!workspace) {\n    throw new Error(`Could not find a ${level} workspace. Are you in a project?`);\n  }\n\n  if (force || isTTY()) {\n    const answer = await askConfirmation(\n      `\nWould you like to share pseudonymous usage data about this project with the Angular Team\nat Google under Google's Privacy Policy at https://policies.google.com/privacy. For more\ndetails and how to change this setting, see https://angular.dev/cli/analytics.\n\n  `,\n      false,\n    );\n\n    await setAnalyticsConfig(global, answer);\n\n    if (answer) {\n      console.log('');\n      console.log(","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/angular/angular-cli/blob/bb72145f9ab45aee29f523236b3a25cd0813a841/packages/angular/cli/src/analytics/analytics.ts#L56-L92","documentation":"promptAnalytics asks the user to opt in to analytics, but it needs a workspace config at the requested level to store the answer. When getWorkspace finds no config at that level, it throws this error with the 'Are you in a project?' hint.","triggerScenarios":"First interactive run of a command that calls promptAnalytics (via getAnalyticsUserId) when there is no local angular.json, or when resolving the global level finds no global config file.","commonSituations":"Running 'ng' inside a folder that is not an Angular project; a CI/non-workspace directory; deleted angular.json; running in a monorepo root that has no Angular workspace config.","solutions":["Run the command from the root directory of an Angular workspace (where angular.json lives)","Create a new workspace with 'ng new' if none exists","Set CI=true or analytics globally to skip local-workspace prompting","Check that angular.json is not gitignored/deleted in your checkout"],"exampleFix":"// before\n~/ randome-dir $ ng build\n// after\ncd ~/projects/my-app && ng build","handlingStrategy":"validation","validationCode":"import { existsSync } from 'fs';\nif (!existsSync('angular.json')) {\n  console.error('Not inside an Angular project; cd to the workspace root first.');\n  process.exit(1);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await promptAnalytics(global, force);\n} catch (e) {\n  if ((e as Error).message.includes('Could not find a')) {\n    // non-project context: skip prompting, use env var default\n    return process.env.NG_CLI_ANALYTICS === 'true';\n  }\n  throw e;\n}","preventionTips":["Run ng commands from the project root","Set NG_CLI_ANALYTICS=false or CI=true in CI to bypass interactive prompting","Ensure angular.json is committed and not removed by scripts"],"tags":["angular-cli","workspace","analytics","project"],"backgroundTag":"workspace-not-found","analyzedSha":"bb72145f9ab45aee29f523236b3a25cd0813a841","analyzedAt":"2026-08-30T02:47:34.745Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}