{"record":{"id":"f4ae8306fe57ec83","repo":"angular/angular-cli","slug":"collection-json-stringify-name-cannot-be-resol-f4ae83","errorCode":null,"errorMessage":"Collection ${JSON.stringify(name)} cannot be resolved.","messagePattern":"Collection (.+?) cannot be resolved\\.","errorType":"exception","errorClass":"CollectionCannotBeResolvedException","httpStatus":null,"severity":"error","filePath":"packages/angular_devkit/schematics/tools/node-module-engine-host.ts","lineNumber":92,"sourceCode":"      if ((e as NodeJS.ErrnoException).code !== 'MODULE_NOT_FOUND') {\n        throw e;\n      }\n    }\n\n    // If not a package, try to resolve as a file\n    if (!collectionPath) {\n      try {\n        collectionPath = require.resolve(name, resolveOptions);\n      } catch (e) {\n        if ((e as NodeJS.ErrnoException).code !== 'MODULE_NOT_FOUND') {\n          throw e;\n        }\n      }\n    }\n\n    // If not a package or a file, error\n    if (!collectionPath) {\n      throw new CollectionCannotBeResolvedException(name);\n    }\n\n    return collectionPath;\n  }\n\n  protected _resolveCollectionPath(name: string, requester?: string): string {\n    const collectionPath = this.resolve(name, requester);\n    readJsonFile(collectionPath);\n\n    return collectionPath;\n  }\n\n  protected _resolveReferenceString(\n    refString: string,\n    parentPath: string,\n    collectionDescription?: FileSystemCollectionDesc,\n  ): { ref: RuleFactory<{}>; path: string } | null {\n    const ref = new ExportStringRef<RuleFactory<{}>>(refString, parentPath);","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/angular/angular-cli/blob/bb72145f9ab45aee29f523236b3a25cd0813a841/packages/angular_devkit/schematics/tools/node-module-engine-host.ts#L74-L110","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before: collection not installed\nng g my-missing-schematics:component\n// after: install the package that provides it first\nnpm install --save-dev @myorg/my-schematics\nng g @myorg/my-schematics:component","handlingStrategy":"validation","validationCode":"function collectionIsResolvable(name) {\n  if (/^\\.?\\.?\\//.test(name)) return require('fs').existsSync(name);\n  try { return !!require.resolve(`${name}/package.json`); } catch { return false; }\n}\nif (!collectionIsResolvable('@myorg/my-schematics')) throw new Error('collection not installed');","typeGuard":"function isStringCollectionName(v) {\n  return typeof v === 'string' && v.trim().length > 0;\n}","tryCatchPattern":"try {\n  const collection = engine.createCollection(collectionName);\n} catch (err) {\n  if (err instanceof CollectionCannotBeResolvedException) {\n    console.error(`Collection \"${collectionName}\" not found: install it or fix the path`);\n  } else { throw err; }\n}","preventionTips":["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."],"tags":["angular","schematics","module-resolution","node"],"backgroundTag":"collection-cannot-be-resolved","analyzedSha":"bb72145f9ab45aee29f523236b3a25cd0813a841","analyzedAt":"2026-08-30T02:47:34.745Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}