angular/angular-cli · error · Error

Could not find global workspace

Error message

Could not find global workspace

What it means

Thrown by setCompletionConfig in the Angular CLI completion utilities when getWorkspace('global') returns undefined, meaning the global Angular workspace/configuration file could not be located or loaded. The function needs it to persist the `cli.completion` setting that records whether the user was prompted for autocompletion setup.

Source

Thrown at packages/angular/cli/src/utilities/completion.ts:110

    );
  }

  // Save configuration to remember that the user was prompted.
  await setCompletionConfig({ ...completionConfig, prompted: true });

  return undefined;
}

async function getCompletionConfig(): Promise<CompletionConfig | undefined> {
  const wksp = await getWorkspace('global');

  return wksp?.getCli()?.['completion'];
}

async function setCompletionConfig(config: CompletionConfig): Promise<void> {
  const wksp = await getWorkspace('global');
  if (!wksp) {
    throw new Error(`Could not find global workspace`);
  }

  wksp.extensions['cli'] ??= {};
  const cli = wksp.extensions['cli'];
  if (!json.isJsonObject(cli)) {
    throw new Error(
      `Invalid config found at ${wksp.filePath}. \`extensions.cli\` should be an object.`,
    );
  }
  cli.completion = config as json.JsonObject;
  await wksp.save();
}

async function shouldPromptForAutocompletionSetup(
  command: string,
  config?: CompletionConfig,
): Promise<boolean> {
  // Force whether or not to prompt for autocomplete to give an easy path for e2e testing to skip.

View on GitHub (pinned to bb72145f9a)

Solutions

  1. Ensure a valid global Angular config exists: run any ng command once or create ~/.angular-config (or the path from NG_CLI_ANALYTICS/global workspace resolution) with valid JSON.
  2. Verify HOME (and XDG_CONFIG_HOME if used) is set and writable; fix the environment in CI/containers.
  3. Inspect the global config file for corruption/parse errors and repair or delete it so it can be regenerated.
  4. Guard the call site: wrap setCompletionConfig in try/catch and log a warning instead of failing the command, since completion setup is non-essential.

Example fix

// before
await setCompletionConfig({ ...completionConfig, prompted: true });
// after
try {
  await setCompletionConfig({ ...completionConfig, prompted: true });
} catch (err) {
  logger.warn(`Could not save completion config: ${(err as Error).message}`);
}
Defensive patterns

Strategy: try-catch

Validate before calling

import { getWorkspace } from './utilities/workspace';
const wksp = await getWorkspace('global');
if (!wksp) {
  logger.warn('No global Angular workspace; skipping completion setup');
  return;
}

Type guard

function isWorkspace(v: unknown): v is { filePath: string; extensions: Record<string, unknown>; save(): Promise<void> } {
  return typeof v === 'object' && v !== null && 'filePath' in v && 'save' in v;
}

Try / catch

try {
  await setCompletionConfig(config);
} catch (err) {
  if ((err as Error).message === 'Could not find global workspace') {
    logger.warn('Completion config not saved: global Angular config missing');
  } else throw err;
}

Prevention

When it happens

Trigger: considerSettingUpAutocompletion reaching the config-save step in an environment where no global config file exists or fails to load (e.g. unreadable/missing ~/.angular-config or equivalent, HOME not resolvable, or workspace creation returning undefined).

Common situations: Running the CLI in containers/CI with no home directory or a read-only HOME, corrupted global Angular config causing getWorkspace to yield undefined, sandboxed environments, or unusual XDG_CONFIG_HOME/HOME setups.

Related errors


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