angularroutesnestjsscaffold

Invalid schematic "route". Please, ensure that "route" exists in this collection


enter image description here Context

[I am new in this field]

I am working on Angular + Nestjs project and I have created new server directory using nest new server and selected yarn as my package manager,

Problem

I then moved into this directory and ran nest generate route cats to scaffold new route directory with necessary resources, but in response I get an error which says: Invalid schematic "route". Please, ensure that "route" exists in this collection.

Read this before you answer

I made sure that I was in root directory of my nest project and there was no typing error.

I also checked for devDependencies in package.json file where "@nestjs/schematics": "^9.0.0", is present.

Can any one tell why am I getting this error and how to fix it? I searched on the internet regarding this but got no satisfactory answer.


Solution

  • I think you're meaning to run nest generate resource cats. There's no route schematic, but there is a resource which can be used to generate CRUD operations


    Edit

    Below is the output of nest g --help. Notice there is no route schematic. Whatever you're looking at that shows a route schematic is either custom, or wrong information

    docker run -it node sh
    # npm i -gs @nestjs/cli             
    npm notice 
    npm notice New minor version of npm available! 9.5.0 -> 9.6.2
    npm notice Changelog: https://github.com/npm/cli/releases/tag/v9.6.2
    npm notice Run npm install -g npm@9.6.2 to update!
    npm notice 
    # nest g --help
    Usage: nest generate|g [options] <schematic> [name] [path]
    
    Generate a Nest element.
      Schematics available on @nestjs/schematics collection:
        ┌───────────────┬─────────────┬──────────────────────────────────────────────┐
        │ name          │ alias       │ description                                  │
        │ application   │ application │ Generate a new application workspace         │
        │ class         │ cl          │ Generate a new class                         │
        │ configuration │ config      │ Generate a CLI configuration file            │
        │ controller    │ co          │ Generate a controller declaration            │
        │ decorator     │ d           │ Generate a custom decorator                  │
        │ filter        │ f           │ Generate a filter declaration                │
        │ gateway       │ ga          │ Generate a gateway declaration               │
        │ guard         │ gu          │ Generate a guard declaration                 │
        │ interceptor   │ itc         │ Generate an interceptor declaration          │
        │ interface     │ itf         │ Generate an interface                        │
        │ library       │ lib         │ Generate a new library within a monorepo     │
        │ middleware    │ mi          │ Generate a middleware declaration            │
        │ module        │ mo          │ Generate a module declaration                │
        │ pipe          │ pi          │ Generate a pipe declaration                  │
        │ provider      │ pr          │ Generate a provider declaration              │
        │ resolver      │ r           │ Generate a GraphQL resolver declaration      │
        │ resource      │ res         │ Generate a new CRUD resource                 │
        │ service       │ s           │ Generate a service declaration               │
        │ sub-app       │ app         │ Generate a new application within a monorepo │
        └───────────────┴─────────────┴──────────────────────────────────────────────┘
    
    Options:
      -d, --dry-run                      Report actions that would be taken without writing out results.
      -p, --project [project]            Project in which to generate files.
      --flat                             Enforce flat structure of generated element.
      --no-flat                          Enforce that directories are generated.
      --spec                             Enforce spec files generation. (default: true)
      --skip-import                      Skip importing (default: false)
      --no-spec                          Disable spec files generation.
      -c, --collection [collectionName]  Schematics collection to use.
      -h, --help                         Output usage information.