NestJS cli error: Collection "@nestjs/schematics" cannot be resolved

To keep using yarn, this worked for me

yarn global add @nestjs/schematics

I had the same problem. same error message. I installed nest with yarn so I use command bellow to add(install) shematics:

yarn global add @nestjs/schematics

If you use npm use this

npm i -g @nestjs/schematics

Initially, I added NestJS cli with yarn and it gave the above error. The issue gets fixed as soon as I've installed NestJS cli with Npm after removing it from yarn.