angular/angular-cli · error · Error

Could not find a ${level} workspace. Are you in a project?

Error message

Could not find a ${level} workspace. Are you in a project?

What it means

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.

Source

Thrown at packages/angular/cli/src/analytics/analytics.ts:74

  cli.analytics = value === true ? randomUUID() : value;
  await workspace.save();
}

/**
 * Prompt the user for usage gathering permission.
 * @param force Whether to ask regardless of whether or not the user is using an interactive shell.
 * @return Whether or not the user was shown a prompt.
 */
export async function promptAnalytics(
  context: CommandContext,
  global: boolean,
  force = false,
): Promise<boolean> {
  const level = global ? 'global' : 'local';
  const workspace = await getWorkspace(level);
  if (!workspace) {
    throw new Error(`Could not find a ${level} workspace. Are you in a project?`);
  }

  if (force || isTTY()) {
    const answer = await askConfirmation(
      `
Would you like to share pseudonymous usage data about this project with the Angular Team
at Google under Google's Privacy Policy at https://policies.google.com/privacy. For more
details and how to change this setting, see https://angular.dev/cli/analytics.

  `,
      false,
    );

    await setAnalyticsConfig(global, answer);

    if (answer) {
      console.log('');
      console.log(

View on GitHub (pinned to bb72145f9a)

Solutions

  1. Run the command from the root directory of an Angular workspace (where angular.json lives)
  2. Create a new workspace with 'ng new' if none exists
  3. Set CI=true or analytics globally to skip local-workspace prompting
  4. Check that angular.json is not gitignored/deleted in your checkout

Example fix

// before
~/ randome-dir $ ng build
// after
cd ~/projects/my-app && ng build
Defensive patterns

Strategy: validation

Validate before calling

import { existsSync } from 'fs';
if (!existsSync('angular.json')) {
  console.error('Not inside an Angular project; cd to the workspace root first.');
  process.exit(1);
}

Try / catch

try {
  await promptAnalytics(global, force);
} catch (e) {
  if ((e as Error).message.includes('Could not find a')) {
    // non-project context: skip prompting, use env var default
    return process.env.NG_CLI_ANALYTICS === 'true';
  }
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of angular/angular-cli@bb72145f9a (2026-08-30). Data as JSON: /api/errors/a17deaf6c9159a34. Report an issue: GitHub.