angular/angular-cli · error · InvalidCollectionJsonException
Collection JSON at path ${JSON.stringify(path)} is invalid.
Error message
Collection JSON at path ${JSON.stringify(path)} is invalid. What it means
createCollectionDescription reads the resolved collection JSON file; if the parsed value is falsy, not an object, or an array, it throws InvalidCollectionJsonException with the file path. The file must be a JSON object describing the collection.
Source
Thrown at packages/angular_devkit/schematics/tools/file-system-engine-host-base.ts:165
}
registerContextTransform(t: ContextTransform): void {
this._contextTransforms.push(t);
}
/**
*
* @param name
* @return {{path: string}}
*/
createCollectionDescription(
name: string,
requester?: FileSystemCollectionDesc,
): FileSystemCollectionDesc {
const path = this._resolveCollectionPath(name, requester?.path);
const jsonValue = readJsonFile(path);
if (!jsonValue || typeof jsonValue != 'object' || Array.isArray(jsonValue)) {
throw new InvalidCollectionJsonException(name, path);
}
// normalize extends property to an array
if (typeof jsonValue['extends'] === 'string') {
jsonValue['extends'] = [jsonValue['extends']];
}
const description = this._transformCollectionDescription(name, {
...jsonValue,
path,
});
if (!description || !description.name) {
throw new InvalidCollectionJsonException(name, path);
}
// Validate aliases.
const allNames = Object.keys(description.schematics);
for (const schematicName of Object.keys(description.schematics)) {View on GitHub (pinned to bb72145f9a)
Solutions
- Fix the collection.json at the printed path so it parses to a non-empty JSON object
- Validate the JSON (e.g. node -e "require('<path>')") to catch syntax errors
- Ensure the referenced package's package.json has a 'schematics' field pointing at the right collection file
- Reinstall/repair the package if its files are truncated (rm -rf node_modules && npm i)
Example fix
// before (collection.json)
[]
// after (collection.json)
{
"$schema": "./node_modules/@angular-devkit/schematics/collection-schema.json",
"schematics": {
"my-schematic": { "factory": "./my-schematic/index" }
}
} Defensive patterns
Strategy: validation
Validate before calling
import { readFileSync } from 'fs';
function isValidCollectionJson(path: string): boolean {
try {
const v = JSON.parse(readFileSync(path, 'utf-8'));
return !!v && typeof v === 'object' && !Array.isArray(v);
} catch { return false; }
} Type guard
function isCollectionObject(v: unknown): v is Record<string, unknown> {
return typeof v === 'object' && v !== null && !Array.isArray(v);
} Try / catch
try {
await workflow.execute({ collection, schematic });
} catch (e) {
if (/Collection JSON at path .* is invalid/.test(String(e))) {
const m = String(e).match(/at path (.+?) is invalid/);
console.error(`Fix the collection file at ${m?.[1]}`);
} else throw e;
} Prevention
- Validate collection.json against the official collection-schema.json
- Never leave merge-conflict markers or empty files in collection JSONs
- Ensure package.json 'schematics' field points to an existing file
- Parse-check custom collections in CI before publishing
When it happens
Trigger: A collection.json (or package.json used as collection) that is empty, contains 'null'/'[]', is truncated/invalid such that readJsonFile returns null, or resolves to a wrong file via _resolveCollectionPath.
Common situations: Hand-edited or corrupted collection.json files; build pipelines emitting empty JSON; misconfigured package.json missing schematics metadata so the wrong file is read; merge conflicts left as invalid JSON.
Related errors
- Collection "${name}" does not have a schematics map.
- Option "project" is required.
- Project is not defined in this workspace.
- Targets are not defined for this project.
- Invalid file replacement: ${JSON.stringify(fileReplacement)}
AI-assisted analysis of angular/angular-cli@bb72145f9a (2026-08-30).
Data as JSON: /api/errors/0514d49853472e70.
Report an issue: GitHub.