You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

执行自定义Schematics 'my-comp'时无法解析工厂问题求助

Fixing "Schematic 'my-comp' cannot resolve the factory" Error

I ran into this exact issue when building custom schematics before, and looking at your code and configuration, the problem comes down to a mismatch between your function export style and the factory path in collection.json.

Here are two straightforward fixes:

Option 1: Update your collection.json to match the default export

Since you're using export default for your schematic function, the factory reference should point to #default instead of #myComp:

{
  "$schema": "../node_modules/@angular-devkit/schematics/collection-schema.json",
  "schematics": {
    "my-comp": {
      "description": "This schematics generate an Angular Component on the current module or in an specified one",
      "factory": "./my-comp/index#default"
    }
  }
}

Option 2: Switch to a named export in your factory code

If you prefer to keep the #myComp reference in your config, change your default export to a named export:

export function myComp(options: IFlexComponentOptions): Rule {
  return (host: Tree, context: SchematicContext) => {
    console.log("options before sanatize", options);
    // ... your existing logic
    return rule(host, context);
  };
}

Why this happens

The Angular DevKit schematics engine looks for the exact export name you specify in collection.json. When you use export default, the internal identifier for that function is default — not the name you gave the function. Your config was trying to find a named export called myComp, which didn't exist, hence the resolution error.

Quick validation steps after fixing

  • If you're using TypeScript, make sure you've compiled your code with tsc (schematics runs against the compiled JavaScript files)
  • Re-run the command: schematics .:my-comp

内容的提问来源于stack exchange,提问作者Jorge C

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.12 04:29:30