angular/angular-cli · critical · Error

Workspace config file cannot be loaded: ${configPath}

Error message

Workspace config file cannot be loaded: ${configPath}

What it means

The CLI's config layer (`getWorkspace`) loads an `angular.json`/`.angular.json` workspace file via `AngularWorkspace.load` and caches it per level (project/global). Any failure while reading or parsing that file is caught and rethrown with this message, with the original error attached as `cause`. It indicates the workspace config file exists (or was resolved) but could not be loaded.

Source

Thrown at packages/angular/cli/src/utilities/config.ts:210

      );

      cachedWorkspaces.set(level, globalWorkspace);

      return globalWorkspace;
    }

    cachedWorkspaces.set(level, undefined);

    return undefined;
  }

  try {
    const workspace = await AngularWorkspace.load(configPath);
    cachedWorkspaces.set(level, workspace);

    return workspace;
  } catch (error) {
    throw new Error(`Workspace config file cannot be loaded: ${configPath}`, { cause: error });
  }
}

/**
 * This method will load the workspace configuration in raw JSON format.
 * When `level` is `global` and file doesn't exists, it will be created.
 *
 * NB: This method is intended to be used only for `ng config`.
 */
export async function getWorkspaceRaw(
  level: 'local' | 'global' = 'local',
): Promise<[JSONFile | null, string | null]> {
  let configPath = level === 'local' ? await projectFilePath() : globalFilePath();

  if (!configPath) {
    if (level === 'global') {
      configPath = defaultGlobalFilePath;
      // Config doesn't exist, force create it.

View on GitHub (pinned to bb72145f9a)

Solutions

  1. Inspect `error.cause` for the underlying parse/load failure and fix that line in `angular.json`.
  2. Validate `angular.json` with a JSON linter: `npx jsonlint angular.json` or `jq . angular.json > /dev/null`.
  3. Restore the file: `git checkout -- angular.json`, or regenerate with `ng new` in a scratch dir and diff.
  4. Confirm the file is readable by the current user and that you are running the CLI from inside the workspace root.

Example fix

// before
{"projects": {"app": {"root": "",}},  // trailing comma -> parse error
// after
{"projects": {"app": {"root": ""}}}
Defensive patterns

Strategy: try-catch

Validate before calling

import { readFile } from 'node:fs/promises';
try {
  JSON.parse(await readFile('angular.json', 'utf8'));
} catch (e) {
  throw new Error('angular.json is missing or invalid; fix before running the CLI.', { cause: e });
}

Type guard

function isWorkspaceLoadError(e: unknown): e is Error {
  return e instanceof Error && e.message.startsWith('Workspace config file cannot be loaded:');
}

Try / catch

try {
  await runNgCommand();
} catch (e: any) {
  if (e instanceof Error && e.message.startsWith('Workspace config file cannot be loaded')) {
    console.error('Root cause:', e.cause); // inspect and fix angular.json
  } else { throw e; }
}

Prevention

When it happens

Trigger: Any CLI command that resolves workspace configuration (via `wksp`, `globalWorkspace`, `workspace`, `globalOptions`) where `AngularWorkspace.load(configPath)` throws — typically invalid JSON, a schema mismatch, or an unreadable file.

Common situations: Hand-edited `angular.json` with a JSON syntax error (trailing comma, comments); file truncated by a bad merge; schema-version mismatch after upgrading the CLI; permission problems on the config file.

Related errors


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