angular-schematics

Schematic "my-comp" cannot resolve the factory


I'm following this book: https://github.com/manfredsteyer/schematics-sample

When I execute my schematics

schematics .:my-comp

I get the following error:

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)

This is part of my factory:

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

my collectyion.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"
    }
  }
}

Solution

  • I had the same problem, from export default function myComp remove the default. And it should work. I follow the same book. Lots of incompatibilities.