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
- Run the schematic inside a directory containing a valid Angular workspace config ('angular.json' / '.angular.json') created via 'ng new' or 'ng generate config'.
- If you maintain the schematic, migrate to '@schematics/angular/utility/workspace' (readWorkspace) instead of the legacy 'utility/config' getWorkspace shim.
- 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.
- 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
- Always run schematics from a directory that contains angular.json (check with 'ls angular.json' or CLI cwd detection).
- Use the modern workspaces.readWorkspace API instead of the legacy utility/config shim.
- When building Trees in tests, always stub the workspace config file.
- Keep CLI and @schematics/angular versions in sync.
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
- schematicName cannot be undefined.
- The "not" keyword is not supported in JSON Schema.
- Unknown schematics built-in module '${id}' requested from sc
- A collection and schematic is required during execution.
- Unknown task dependency [ID: ${id.id}].
AI-assisted analysis of angular/angular-cli@bb72145f9a (2026-08-30).
Data as JSON: /api/errors/65b311bd367e2d04.
Report an issue: GitHub.