angular/angular-cli · error · SchematicsException

Could not find (/.angular.json)

Error message

Could not find (/.angular.json)

What it means

This SchematicsException is thrown by the legacy '@schematics/angular/utility/config' getWorkspace shim in the Angular CLI's SchematicEngineHost. When a schematic asks for the workspace configuration, the shim reads the virtual '/.angular.json' path from the host tree and, if no data exists, throws 'Could not find (/.angular.json)'. It exists to keep old schematics (written before angular.json replaced .angular.json) working with modern workspaces.

Source

Thrown at packages/angular/cli/src/command-builder/utilities/schematic-engine-host.ts:112

      return { ref: factory, path: schematicPath };
    }

    // All other schematics use default behavior
    return super._resolveReferenceString(refString, parentPath, collectionDescription);
  }
}

/**
 * Minimal shim modules for legacy deep imports of `@schematics/angular`
 */
const legacyModules: Record<string, unknown> = {
  '@schematics/angular/utility/config': {
    getWorkspace(host: Tree) {
      const path = '/.angular.json';
      const data = host.read(path);
      if (!data) {
        throw new SchematicsException(`Could not find (${path})`);
      }

      return parseJson(data.toString(), [], { allowTrailingComma: true });
    },
  },
  '@schematics/angular/utility/project': {
    buildDefaultPath(project: { sourceRoot?: string; root: string; projectType: string }): string {
      const root = project.sourceRoot ? `/${project.sourceRoot}/` : `/${project.root}/src/`;

      return `${root}${project.projectType === 'application' ? 'app' : 'lib'}`;
    },
  },
};

/**
 * Wrap a JavaScript file in a VM context to allow specific Angular dependencies to be redirected.
 * This VM setup is ONLY intended to redirect dependencies.
 *

View on GitHub (pinned to bb72145f9a)

Solutions

  1. Run the schematic inside a directory containing a valid Angular workspace config ('angular.json' / '.angular.json') created via 'ng new' or 'ng generate config'.
  2. If you maintain the schematic, migrate to '@schematics/angular/utility/workspace' (readWorkspace) instead of the legacy 'utility/config' getWorkspace shim.
  3. If constructing a Tree programmatically, add a workspace config: host.create('/.angular.json', Buffer.from(JSON.stringify(workspace))) or '/angular.json' depending on the host lookup.
  4. Upgrade the CLI/schematic package versions so both sides agree on the config file name.

Example fix

// before (legacy schematic)
import { getWorkspace } from '@schematics/angular/utility/config';
const workspace = getWorkspace(tree);

// after
import { workspaces } from '@angular-devkit/core';
import { createWorkspaceHost } from '@angular-devkit/architect/node';
const { workspace } = await workspaces.readWorkspace('/', createWorkspaceHost(tree));
Defensive patterns

Strategy: validation

Validate before calling

import { Tree } from '@angular-devkit/schematics';
function hasWorkspaceConfig(host: Tree): boolean {
  return host.exists('/angular.json') || host.exists('/.angular.json');
}
if (!hasWorkspaceConfig(tree)) {
  throw new Error('Not inside an Angular workspace: no angular.json found');
}

Type guard

function isWorkspaceTree(host: Tree): host is Tree & { __hasWorkspace: true } {
  return (host as Tree).exists('/angular.json') || (host as Tree).exists('/.angular.json');
}

Try / catch

try {
  const workspace = getWorkspace(tree);
} catch (e) {
  if (e instanceof SchematicsException && /Could not find \(/.test(e.message)) {
    // fall back to modern readWorkspace or abort with a friendly message
  } else { throw e; }
}

Prevention

When it happens

Trigger: A schematic requires '@schematics/angular/utility/config' and calls its getWorkspace(host) while the host tree contains no '/.angular.json' file — i.e. the workspace config is named 'angular.json' (modern default) or is missing entirely from the tree the host serves.

Common situations: Running an old schematic or generator (pre-v6 style) in a modern CLI workspace where the config is 'angular.json' not '.angular.json'; running schematics outside a real Angular workspace (no config file at all); tools that build a virtual Tree programmatically and forgot to stub the workspace config.

Related errors


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