原理图“my-comp”无法解析工厂

Posted

技术标签:

【中文标题】原理图“my-comp”无法解析工厂【英文标题】:Schematic "my-comp" cannot resolve the factory 【发布时间】:2019-08-09 23:11:34 【问题描述】:

我正在关注这本书:https://github.com/manfredsteyer/schematics-sample

当我执行我的原理图时

schematics .:my-comp

我收到以下错误:

An error occured:
Error: Schematic "my-comp" cannot resolve the factory.
    at NodeModulesEngineHost.createSchematicDescription (/home/.../.npm-global/lib/node_modules/@angular-devkit/schematics-cli/node_modules/@angular-devkit/schematics/tools/file-system-engine-host-base.js:174:19)
    at SchematicEngine.createSchematic (/home/.../.npm-global/lib/node_modules/@angular-devkit/schematics-cli/node_modules/@angular-devkit/schematics/src/engine/engine.js:219:38)
    at CollectionImpl.createSchematic (/home/.../.npm-global/lib/node_modules/@angular-devkit/schematics-cli/node_modules/@angular-devkit/schematics/src/engine/engine.js:69:29)
    at NodeWorkflow.execute (/home/.../.npm-global/lib/node_modules/@angular-devkit/schematics-cli/node_modules/@angular-devkit/schematics/src/workflow/base.js:99:38)
    at main (/home/.../.npm-global/lib/node_modules/@angular-devkit/schematics-cli/bin/schematics.js:202:24)
    at Object.<anonymous> (/home/.../.npm-global/lib/node_modules/@angular-devkit/schematics-cli/bin/schematics.js:293:5)
    at Module._compile (internal/modules/cjs/loader.js:701:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Module.load (internal/modules/cjs/loader.js:600:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:539:12)

这是我工厂的一部分:

    export default function myComp(options: IFlexComponentOptions): Rule 
  return (host: Tree, context: SchematicContext) => 
    console.log("options before sanatize", options);
    ...
    return rule(host, context);
  ;

我的 collectionion.json


  "$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#myComp"
    
  

【问题讨论】:

【参考方案1】:

我遇到了同样的问题,从 export default function myComp 删除 default。它应该工作。我遵循同一本书。很多不兼容的地方。

【讨论】:

这与 collections.json 文件如何引用工厂有关 - 如果您将函数导出为默认值,则不需要工厂引用中的 #helloWorld。如果您确实保留了哈希,那将是导出函数的名称,在本例中为helloWorld,如果它被导出,则默认函数名称不存在。因此,要引用默认导出,请不要在 collection.json 工厂属性中包含哈希,并且在没有默认导出的情况下,您需要哈希来识别要引用的导出函数。

以上是关于原理图“my-comp”无法解析工厂的主要内容,如果未能解决你的问题,请参考以下文章

创建在类路径资源[applicationcontext]中定义名为“工厂”的bean时出错。:在设置bean属性“dataSource”时,无法解析对bean“dataSource”的引用;嵌套异常是

条形图不工作(无法解析类.....charts.BarChart)

AOP 工厂对象之ScopedProxyFactoryBean 原理解析

Spark运行原理和RDD解析(DT大数据梦工厂)

Spring基础:IOC底层原理

深度解析spring源码IOC原理