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

  1. Open the file named in the error and make the 'cli' key an object, e.g. {"cli": {"analytics": false}}
  2. Validate angular.json is valid JSON with a JSON linter
  3. Restore the config from version control or regenerate it
  4. 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

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


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