angular/angular-cli · error · Error
Invalid config found at ${workspace.filePath}. CLI should be
Error message
Invalid config found at ${workspace.filePath}. CLI should be an object. What it means
After loading the workspace config, setAnalyticsConfig validates that the 'cli' extension entry is a JSON object before assigning cli.analytics. If the config file exists but its 'cli' section (or structure) is not an object, it throws this error including the offending config file path.
Source
Thrown at packages/angular/cli/src/analytics/analytics.ts:54
}
});
}
/**
* 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,
global: boolean,
force = false,
): Promise<boolean> {
const level = global ? 'global' : 'local';
const workspace = await getWorkspace(level);View on GitHub (pinned to bb72145f9a)
Solutions
- Open the file named in the error and make the 'cli' key an object, e.g. {"cli": {"analytics": false}}
- Validate angular.json is valid JSON with a JSON linter
- Restore the config from version control or regenerate it
- Remove the malformed 'cli' key and re-run the analytics command to recreate it
Example fix
// before (angular.json extensions)
"cli": "disabled"
// after
"cli": {"analytics": false} Defensive patterns
Strategy: validation
Validate before calling
import { readFileSync } from 'fs';
const cfg = JSON.parse(readFileSync('angular.json', 'utf8'));
const cli = cfg.cli ?? cfg.extensions?.cli;
if (cli !== undefined && (typeof cli !== 'object' || cli === null || Array.isArray(cli))) {
throw new Error('cli section must be an object');
} Type guard
function isJsonObject(v: unknown): v is Record<string, unknown> {
return typeof v === 'object' && v !== null && !Array.isArray(v);
} Try / catch
try {
await setAnalyticsConfig(global, value);
} catch (e) {
if ((e as Error).message.startsWith('Invalid config found at')) {
const filePath = (e as Error).message.match(/at (.+)\./)?.[1];
// repair or restore the named config file
} else throw e;
} Prevention
- Never set "cli" to a plain string in angular.json
- Edit config with 'ng config' instead of by hand
- Validate angular.json with a JSON schema linter
- Keep config files in version control to diff/restore bad edits
When it happens
Trigger: A global or local Angular config file where 'cli' is a string, number, array or null (e.g. hand-edited angular.json or ~/.angular-config.json with "cli": "disabled"), or corrupted/malformed config merging.
Common situations: Manual edits to angular.json; copy-pasted config snippets; older config formats after CLI upgrades; tools that rewrote the config incorrectly.
Related errors
- Workspace config file cannot be loaded: ${configPath}
- Failed to parse "${path}" as JSON AST Object. ${printParseEr
- Invalid collection.json; schematics needs to be an object.
- Could not find ${level} workspace.
- 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/2ea842539e49d12d.
Report an issue: GitHub.