angular/angular-cli · error · Error
Could not find ${level} workspace.
Error message
Could not find ${level} workspace. What it means
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.
Source
Thrown at packages/angular/cli/src/analytics/analytics.ts:49
return analyticsPackageSafelist.some((pattern) => {
if (typeof pattern == 'string') {
return pattern === name;
} else {
return pattern.test(name);
}
});
}
/**
* Set analytics settings. This does not work if the user is not inside a project.
* @param global Which config to use. "global" for user-level, and "local" for project-level.
* @param value Either a user ID, true to generate a new User ID, or false to disable analytics.
*/
export async function setAnalyticsConfig(global: boolean, value: string | boolean): Promise<void> {
const level = global ? 'global' : 'local';
const workspace = await getWorkspace(level);
if (!workspace) {
throw new Error(`Could not find ${level} workspace.`);
}
const cli = (workspace.extensions['cli'] ??= {});
if (!workspace || !json.isJsonObject(cli)) {
throw new Error(`Invalid config found at ${workspace.filePath}. CLI should be an object.`);
}
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,View on GitHub (pinned to bb72145f9a)
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
Example fix
// before (run in ~/scripts, outside any project) ng analytics disable // after cd ~/my-app && ng analytics disable
Defensive patterns
Strategy: validation
Validate before calling
import { existsSync } from 'fs';
import { homedir } from 'os';
import { join } from 'path';
function workspaceConfigExists(global: boolean): boolean {
return global
? existsSync(join(homedir(), '.angular-config'))
: existsSync(join(process.cwd(), 'angular.json'));
}
if (!workspaceConfigExists(global)) {
// skip the call or create the config first
} Try / catch
try {
await setAnalyticsConfig(global, value);
} catch (e) {
if ((e as Error).message.includes('Could not find')) {
logger.warn(`No ${global ? 'global' : 'local'} workspace config; skipping analytics setting.`);
} else {
throw e;
}
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Could not find a ${level} workspace. Are you in a project?
- Cannot retrieve cache configuration as workspace is not defi
- Confguration file cannot be found.
- Workspace config file cannot be loaded: ${configPath}
- Invalid config found at ${workspace.filePath}. CLI should be
AI-assisted analysis of angular/angular-cli@bb72145f9a (2026-08-30).
Data as JSON: /api/errors/342d8985d981861d.
Report an issue: GitHub.