Angular CLI Error: The serve command requires to b

2020-01-24 10:48发布

When running the terminal commands ng server or ng serve --live-reload=true, I'm getting this issue:

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

30条回答
我欲成王,谁敢阻挡
2楼-- · 2020-01-24 11:04

In my case, I forgot to change my directory, so just after running the command :

ng new AngularProject

execute another command :

cd AngularProject

and ng serve worked for me.

查看更多
时光不老,我们不散
3楼-- · 2020-01-24 11:06

I had the same issue with Angular7 because we need to go the root folder before run your application. Go to the root folder of your app and run the command. It works perfectly for me.

查看更多
趁早两清
4楼-- · 2020-01-24 11:07

I would suggest to confirm if you are in the directory of the project.

查看更多
Explosion°爆炸
5楼-- · 2020-01-24 11:09

This error may be occur when we are in wrong directory.so use cd command to change your directory. It's not very evident from the above comment that which specific command is giving this error so this answer is based on assumption that you are running ng serve outside the root folder/actual project folder. That's why it's giving error because cli commands require conf & build files to run the cli build.

These should be the steps:
npm install -g @angular/cli  //corrected from 'angular-cli'
ng new projectname
cd projectname
ng serve
open http://localhost:4200
查看更多
forever°为你锁心
6楼-- · 2020-01-24 11:09

Tried all the above But for me it was solved by

npm start

查看更多
Viruses.
7楼-- · 2020-01-24 11:10

This happens when you try to run the Angular command "ng s" or "ng serve" on the other folder instead of the root folder of the Angular application.

Also upgrade the Angular using the following command:

ng update @angular/cli --migrate-only --from=1.7.4

This will sort it out.

查看更多
登录 后发表回答