Angular Schematics: Not found : my-schematic error

1.8k views Asked by At

I build a simple Angular Schematics called: my-schematics.

I able to add (using angular cli) my-schematics to some project.

The problem when I run ng update my-schematics I got an error says: Not found : my-schematic.

I'm not sure why. this is my collection.json:

    "schematics": {
      "update": {
        "description": "Updates version test",
        "factory": "./ng-update/index#update"
      }
    }
3

There are 3 answers

0
Stefan van de Vooren On

In the collection.json your schematic is named 'update' instead of my-schematics.

If you want to run your schematic you should

ng g update

Instead of ng update my-schematics

collection.json Within angular.json you could add the default collection for your schematics:

"cli": {
  "defaultCollection": "<path-to-your-collection>/collection.json",
}

If you collection is not the default collection, you should run it by

ng g <your-collection>:<your-schematic-name>

Have a look at https://blog.angular.io/schematics-an-introduction-dc1dfbc2a2b2 to learn more about schematics

0
dingjules On

Try to rename your "update" to "ng-update", and you need to define the schema.json

"schematics": {
  "ng-update": {
    "description": "Updates version test",
    "factory": "./ng-update/index#update",
    "schema": "./ng-update/schema.json" // schema.json to add
  }
}
0
itay oded On

The problem is that you have to install your schematics first, so it will be under your node_modules folder. I do that by running npm install after I build it.

take a look at this blog: https://medium.com/swlh/automate-your-teams-boilerplates-by-building-your-own-schematics-640949001d46?source=friends_link&sk=4b90f9ecc092b598e75c5bbbd6e473a1

it pretty much covers it.