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
- Install the package that contains the collection (npm install / pnpm add the exact name referenced by --collection or schematicName:collection).
- 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')").
- If referencing a local collection file, use a correct relative/absolute path that exists from the working directory of the CLI invocation.
- 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
- Add the schematics package to devDependencies of every project that uses `ng g` with it.
- Run CLI commands from the project root so relative collection paths and node_modules resolve correctly.
- Verify with `node -e "require.resolve('@scope/pkg/package.json')"` before invoking schematics.
- In monorepos, register schematics packages in workspaces or use npm link during development.
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
- Unknown schematics built-in module '${id}' requested from sc
- Option "project" is required.
- Project is not defined in this workspace.
- Targets are not defined for this project.
- Content at path "${this.path}" has changed between the start
AI-assisted analysis of angular/angular-cli@bb72145f9a (2026-08-30).
Data as JSON: /api/errors/f4ae8306fe57ec83.
Report an issue: GitHub.