angular/angular-cli · error · CollectionCannotBeResolvedException

Collection ${JSON.stringify(name)} cannot be resolved.

Error message

Collection ${JSON.stringify(name)} cannot be resolved.

What it means

Thrown by _resolveCollectionPath in FileSystemEngineHost when a collection.json cannot be located for the given name. The host tries require.resolve('<root>/<name>/collection.json') and falls through to this exception when resolution fails or the file does not exist.

Source

Thrown at packages/angular_devkit/schematics/tools/file-system-engine-host.ts:48

  protected _resolveCollectionPath(name: string): string {
    try {
      // Allow `${_root}/${name}.json` as a collection.
      const maybePath = require.resolve(join(this._root, name + '.json'));
      if (existsSync(maybePath)) {
        return maybePath;
      }
    } catch (error) {}

    try {
      // Allow `${_root}/${name}/collection.json.
      const maybePath = require.resolve(join(this._root, name, 'collection.json'));
      if (existsSync(maybePath)) {
        return maybePath;
      }
    } catch (error) {}

    throw new CollectionCannotBeResolvedException(name);
  }

  protected _resolveReferenceString(
    refString: string,
    parentPath: string,
  ): { ref: RuleFactory<{}>; path: string } | null {
    // Use the same kind of export strings as NodeModule.
    const ref = new ExportStringRef<RuleFactory<{}>>(refString, parentPath);
    if (!ref.ref) {
      return null;
    }

    return { ref: ref.ref, path: ref.module };
  }

  protected _transformCollectionDescription(
    name: string,
    desc: Partial<FileSystemCollectionDesc>,

View on GitHub (pinned to bb72145f9a)

Solutions

  1. Install the collection package: npm install <collection-name> (or link it locally with npm link).
  2. Verify the package ships a collection.json at its root and the name passed matches the package name exactly.
  3. Check the engine's _root — construct the FileSystemEngineHost with the correct base path for resolution.
  4. If using a local collection, build it and point the engine root at the directory containing it.

Example fix

// before (package not installed)
const engine = new FileSystemEngineHost(process.cwd());
engine.createCollection('@myorg/schematics'); // throws
// after
// npm install @myorg/schematics
const engine = new FileSystemEngineHost(path.join(process.cwd(), 'node_modules'));
engine.createCollection('@myorg/schematics');
Defensive patterns

Strategy: validation

Validate before calling

import { existsSync } from 'fs';
import { join } from 'path';
const root = join(process.cwd(), 'node_modules');
const p = join(root, name, 'collection.json');
if (!existsSync(p)) throw new Error(`Collection '${name}' not installed (expected ${p}); run npm install ${name}`);

Try / catch

try {
  const collection = engine.createCollection(name);
} catch (e) {
  if (String(e.message).includes('cannot be resolved')) {
    console.error(`Install '${name}' or fix the engine root path`);
    process.exitCode = 1;
  } else throw e;
}

Prevention

When it happens

Trigger: Calling engine.createCollection(name) where <root>/<name>/collection.json does not exist; a misspelled collection name; running outside a directory containing node_modules with the target package installed.

Common situations: ng generate with a collection package not installed (forgot npm install); a private package name typo in --collection; working in a repo where the local collection is not linked/built; requiring the engine with a _root that doesn't point to a node_modules directory.

Related errors


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