{"record":{"id":"521be2ca0e927c72","repo":"angular/angular-cli","slug":"schematic-json-stringify-name-cannot-resolve-t","errorCode":null,"errorMessage":"Schematic ${JSON.stringify(name)} cannot resolve the factory.","messagePattern":"Schematic (.+?) cannot resolve the factory\\.","errorType":"exception","errorClass":"FactoryCannotBeResolvedException","httpStatus":null,"severity":"error","filePath":"packages/angular_devkit/schematics/tools/file-system-engine-host-base.ts","lineNumber":246,"sourceCode":"        const extendCollection = this.createCollectionDescription(collectionName);\n\n        return this.createSchematicDescription(schematicName, extendCollection);\n      } else {\n        return this.createSchematicDescription(schematicName, collection);\n      }\n    }\n    // Use any on this ref as we don't have the OptionT here, but we don't need it (we only need\n    // the path).\n    if (!partialDesc.factory) {\n      throw new SchematicMissingFactoryException(name);\n    }\n    const resolvedRef = this._resolveReferenceString(\n      partialDesc.factory,\n      collectionPath,\n      collection,\n    );\n    if (!resolvedRef) {\n      throw new FactoryCannotBeResolvedException(name);\n    }\n\n    let schema = partialDesc.schema;\n    let schemaJson: JsonObject | undefined = undefined;\n    if (schema) {\n      if (!isAbsolute(schema)) {\n        schema = join(collectionPath, schema);\n      }\n      schemaJson = readJsonFile(schema) as JsonObject;\n    }\n\n    // The schematic path is used to resolve URLs.\n    // We should be able to just do `dirname(resolvedRef.path)` but for compatibility with\n    // Bazel under Windows this directory needs to be resolved from the collection instead.\n    // This is needed because on Bazel under Windows the data files (such as the collection or\n    // url files) are not in the same place as the compiled JS.\n    const maybePath = join(collectionPath, partialDesc.factory);\n    const path =","sourceCodeStart":228,"sourceCodeEnd":264,"githubUrl":"https://github.com/angular/angular-cli/blob/bb72145f9ab45aee29f523236b3a25cd0813a841/packages/angular_devkit/schematics/tools/file-system-engine-host-base.ts#L228-L264","documentation":"Thrown by createSchematicDescription when the `factory` string is present but _resolveReferenceString cannot load it — the module or exported function does not exist at the referenced path. The declaration is valid JSON but the code it points to cannot be resolved.","triggerScenarios":"collection.json `factory` value like \"./foo/index#bar\" where ./foo/index does not exist, is not compiled, or does not export `bar`; _resolveReferenceString returns null and FactoryCannotBeResolvedException is thrown.","commonSituations":"Running a TypeScript collection without compiling to JS first; a refactor renamed the factory function without updating collection.json; a wrong relative path after moving files; publishing a package without the factory files included in the npm package.","solutions":["Check the factory path and exported name in collection.json against the actual file and its exports.","Compile the TypeScript sources (tsc) if the factory lives in uncompiled .ts files.","If publishing, ensure the factory files are included in package.json `files` and shipped to npm.","Ensure the module's dependencies are installed (node_modules present at the collection root)."],"exampleFix":"// before (collection.json)\n\"my-schematic\": { \"factory\": \"./src/index#generate\" }\n// after (path matches compiled output and export name)\n\"my-schematic\": { \"factory\": \"./my-schematic/index#mySchematicGenerator\" }","handlingStrategy":"validation","validationCode":"import { existsSync } from 'fs';\nconst coll = JSON.parse(readFileSync('collection.json', 'utf8'));\nfor (const [name, s] of Object.entries(coll.schematics)) {\n  if (s.factory) {\n    const [file, fn] = String(s.factory).split('#');\n    if (!existsSync(require.resolve(file, { paths: [collectionDir] }))) throw new Error(`Schematic '${name}': ${file} not found`);\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  const schematic = collection.createSchematic(name, true);\n} catch (e) {\n  if (String(e.message).includes('cannot resolve the factory')) {\n    console.error('Check the factory path/export and compile TS before running');\n  } else throw e;\n}","preventionTips":["Always build (tsc) the collection before pointing tools at it; wire build into prepublishOnly.","Smoke-test every schematic with SchematicTestRunner in CI, which resolves factories like production does.","Include compiled factory files in the npm package (files field); avoid referencing src/ directly."],"tags":["schematics","module-resolution","configuration"],"backgroundTag":"factory-cannot-be-resolved","analyzedSha":"bb72145f9ab45aee29f523236b3a25cd0813a841","analyzedAt":"2026-08-30T02:47:34.745Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}