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

at the time I'm going to create component using ng g component command I facing with this error what I need to do to solve this.

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



Solution 1:[1]

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

Solution 2:[2]

  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.

Solution 3:[3]

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.

Solution 4:[4]

You can also get this behavior if you are confusing ng new with ng g application .

Solution 5:[5]

first

cd "project name"

then

ng serve or npm start

Solution 6:[6]

After ng new project make sure you entered project directory in terminal.

Solution 7:[7]

first you check whether you are in workspace location or in your angular-application location. If you are in workspace location then type in command prompt

\workspace>cd angular-application

now you are in following location \workspace\angular-application> here you type ng serve then your application compile and build

\workspace\angular-application>ng serve

you getting below information

C:\Users\venkat\Documents\angular\myfirstangular>ng serve --port 4300

Angular Live Development Server is listening on localhost:4300, open your browser on http://localhost:4300/ 95% emitting CopyPlugini ?wdm?: wait until bundle finished: /

Date: 2019-02-12T18:15:21.157Z

chunk {styles} styles.js, styles.js.map (styles) 16.3 kB [initial] [rendered] chunk {vendor} vendor.js, vendor.js.map (vendor) 3.75 MB [initial] [rendered] i ?wdm?: Compiled successfully.

Solution 8:[8]

you need to add fire npm install command in your root directory of project then npm start. it works for me

Solution 9:[9]

Navigate to project folder and execute command again

Solution 10:[10]

Run ng serve command in client folder