The generate command requires to be run in an Angular project, but a project definition could not be found

If you trying to add new component to an existing project, you should install packages on your system first.

run this code on your console at your root project folder:

npm install

  1. Check you are in correct project or not.
  2. Check angular.json file in your project first,if it is missing,add file.
  3. Update angular CLI.

Your project folder must either contain angular.json or angular-cli.json.

The above mentioned file contains your project definition and its structure. So, that's why without these files and without angular-cli installed. You won't be able to run, ng g component command successfully.

Tags:

Angular