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
- 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
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
- 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
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
- Could not find ${level} workspace.
- Cannot determine project for command. This is a multi-projec
- A workspace is required for this command.
- This command is not available when running the Angular CLI $
- Cannot retrieve cache configuration as workspace is not defi
AI-assisted analysis of angular/angular-cli@bb72145f9a (2026-08-30).
Data as JSON: /api/errors/a17deaf6c9159a34.
Report an issue: GitHub.