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 from resolve() in packages/angular_devkit/schematics/tools/node-module-engine-host.ts:92 when the host could not resolve the collection name to any path: it is neither a resolvable npm package (require.resolve of `${name}/package.json` threw) nor an existing file on disk, so `collectionPath` stays undefined. The schematics engine needs a concrete path to a collection JSON file to load a collection.

Source

Thrown at packages/angular_devkit/schematics/tools/node-module-engine-host.ts:92

      if ((e as NodeJS.ErrnoException).code !== 'MODULE_NOT_FOUND') {
        throw e;
      }
    }

    // If not a package, try to resolve as a file
    if (!collectionPath) {
      try {
        collectionPath = require.resolve(name, resolveOptions);
      } catch (e) {
        if ((e as NodeJS.ErrnoException).code !== 'MODULE_NOT_FOUND') {
          throw e;
        }
      }
    }

    // If not a package or a file, error
    if (!collectionPath) {
      throw new CollectionCannotBeResolvedException(name);
    }

    return collectionPath;
  }

  protected _resolveCollectionPath(name: string, requester?: string): string {
    const collectionPath = this.resolve(name, requester);
    readJsonFile(collectionPath);

    return collectionPath;
  }

  protected _resolveReferenceString(
    refString: string,
    parentPath: string,
    collectionDescription?: FileSystemCollectionDesc,
  ): { ref: RuleFactory<{}>; path: string } | null {
    const ref = new ExportStringRef<RuleFactory<{}>>(refString, parentPath);

View on GitHub (pinned to bb72145f9a)

Solutions

  1. Install the package that contains the collection (npm install / pnpm add the exact name referenced by --collection or schematicName:collection).
  2. Verify the collection name spelling and that `require.resolve('<name>/package.json')` works from your project root (node -e "require.resolve('@scope/pkg/package.json')").
  3. If referencing a local collection file, use a correct relative/absolute path that exists from the working directory of the CLI invocation.
  4. In monorepos/workspaces, link the schematics package (npm link, workspace config) or rebuild it so node_modules contains it.

Example fix

// before: collection not installed
ng g my-missing-schematics:component
// after: install the package that provides it first
npm install --save-dev @myorg/my-schematics
ng g @myorg/my-schematics:component
Defensive patterns

Strategy: validation

Validate before calling

function collectionIsResolvable(name) {
  if (/^\.?\.?\//.test(name)) return require('fs').existsSync(name);
  try { return !!require.resolve(`${name}/package.json`); } catch { return false; }
}
if (!collectionIsResolvable('@myorg/my-schematics')) throw new Error('collection not installed');

Type guard

function isStringCollectionName(v) {
  return typeof v === 'string' && v.trim().length > 0;
}

Try / catch

try {
  const collection = engine.createCollection(collectionName);
} catch (err) {
  if (err instanceof CollectionCannotBeResolvedException) {
    console.error(`Collection "${collectionName}" not found: install it or fix the path`);
  } else { throw err; }
}

Prevention

When it happens

Trigger: Calling EngineHost.createCollection / `ng g` with a collection name that is not installed and not a file path — e.g. `--collection=@scope/not-installed`, or a relative path like `./my-schematics.json` that does not exist, or `schematics` CLI run outside the project folder where a locally referenced collection is missing.

Common situations: Forgetting to `npm install` the package containing the custom schematics; wrong package name/version in dependencies; running the CLI from a different directory so relative collection paths break; node_modules pruned or a monorepo workspace where the package isn't linked; passing a collection name without a valid npm scope.

Related errors


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