angular/angular-cli · error · Error
${message}
Error message
${message} What it means
The workspace JSON reader registers an `error` callback with the JSON parser that unconditionally throws a plain `Error(message)`. Whenever the parser encounters invalid JSON or workspace content that violates the parser's expectations, this callback fires with a descriptive message. It is the generic parse-failure path for workspace (angular.json) parsing; diagnostic reporting is not yet wired up, so the raw parser message is surfaced as a thrown error.
Source
Thrown at packages/angular_devkit/core/src/workspace/json/reader.ts:80
if (version !== 1) {
throw new Error(`Invalid format version detected - Expected:[ 1 ] Found: [ ${version} ]`);
}
const context: ParserContext = {
host,
metadata: new JsonWorkspaceMetadata(path, ast, raw),
trackChanges: true,
unprefixedWorkspaceExtensions: new Set([
...ANGULAR_WORKSPACE_EXTENSIONS,
...(options.allowedWorkspaceExtensions ?? []),
]),
unprefixedProjectExtensions: new Set([
...ANGULAR_PROJECT_EXTENSIONS,
...(options.allowedProjectExtensions ?? []),
]),
error(message, _node) {
// TODO: Diagnostic reporting support
throw new Error(message);
},
warn(message, _node) {
// TODO: Diagnostic reporting support
// eslint-disable-next-line no-console
console.warn(message);
},
};
const workspace = parseWorkspace(ast, context);
return workspace;
}
function parseWorkspace(workspaceNode: Node, context: ParserContext): WorkspaceDefinition {
const jsonMetadata = context.metadata;
let projects;
let extensions: Record<string, JsonValue> | undefined;
if (!context.trackChanges) {View on GitHub (pinned to bb72145f9a)
Solutions
- Validate angular.json with JSON.parse or a linter to find the syntax error at the location named in the message
- Restore the workspace file from version control or regenerate it (e.g. `ng new` comparison)
- If thrown on programmatically supplied content, fix the JSON string/AST before passing it to parseWorkspace
Example fix
// before
const workspace = JSON.parse(fs.readFileSync('angular.json', 'utf8').replace(/^\ufeff/, ''));
parseWorkspace(host, logger, workspaceText, options);
// after
let workspaceText = fs.readFileSync('angular.json', 'utf8');
try {
JSON.parse(workspaceText); // validate first
} catch (e) {
workspaceText = workspaceText.replace(/^\ufeff/, '');
JSON.parse(workspaceText); // surface precise JSON syntax error
}
parseWorkspace(host, logger, workspaceText, options); Defensive patterns
Strategy: try-catch
Validate before calling
try { JSON.parse(workspaceText); } catch (e) { throw new Error(`angular.json is not valid JSON: ${e.message}`); } Try / catch
let workspace;
try {
workspace = await parseWorkspace(host, logger, text, options);
} catch (err) {
// reader throws plain Error with the parser message
console.error(`Failed to parse workspace: ${err.message}`);
process.exitCode = 1;
} Prevention
- Validate angular.json with JSON.parse or a JSON schema linter in CI before running workspace tooling
- Strip BOM and enforce UTF-8 when writing config files
- Never hand-edit angular.json without running a JSON formatter afterwards
When it happens
Trigger: Calling parseWorkspace/parseProject on content where the JSON parser's error callback fires: malformed JSON syntax, wrong node types where structures are expected, or other parser-level validation failures inside angular_devkit/core's JSON AST parser.
Common situations: Hand-edited angular.json with a syntax error (trailing comma, unquoted key); a tool wrote non-JSON content to the workspace file; encoding/BOM issues in the config file.
Related errors
- Workspace config file cannot be loaded: ${configPath}
- Failed to parse "${path}" as JSON AST Object. ${printParseEr
- Project "${projectName}" is missing a required property "roo
- Could not find ${level} workspace.
- Invalid config found at ${workspace.filePath}. CLI should be
AI-assisted analysis of angular/angular-cli@bb72145f9a (2026-08-30).
Data as JSON: /api/errors/e3405a2569ccb8f0.
Report an issue: GitHub.