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:17

Also make sure if you are running ng serve that you stop it first...

查看更多
【Aperson】
3楼-- · 2020-01-24 11:17

Happened to me when didn't install angular core:

Angular CLI: 9.0.0-rc.0
Node: 11.12.0
OS: darwin x64
Angular: undefined
...

So I run

npm i @angular/core

which gave me ng -v

Angular CLI: 9.0.0-rc.0
Node: 11.12.0
OS: darwin x64
Angular: 8.2.13
... core

Then I run

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

removed node_modules

npm install
cd <project name>
ng serve

And it worked!

** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ ** ℹ 「wdm」: Compiled successfully.

查看更多
Juvenile、少年°
4楼-- · 2020-01-24 11:18

It was happening in my existing project as I tried to update to latest node and npm packages:

  1. Uninstall global: npm uninstall -g angular-cli
  2. Reset Cache: npm cache clean or npm cache verify (for npm version > 5)
  3. Install latest: npm install -g @angular/cli@latest
查看更多
做个烂人
5楼-- · 2020-01-24 11:18

to reinstall back freshly the application is way better rather than update or editing some config that is not recognize by npm due to missing config or we are not really sure what is wrong.

I choose @Tinu solution is work

Step 1) npm install -g @angular/cli

Step 2) ng new my-angular-project

Step 3) cd my-angular-project

Step 4) ng serve --open

just made backup for our current source code and put it back to new angular project that be created.

查看更多
够拽才男人
6楼-- · 2020-01-24 11:20

This fixed my problem:

ng generate component nameComponent --module app.module
查看更多
够拽才男人
7楼-- · 2020-01-24 11:21

Finally, the command below fixed the issue for me!

ng update --all --force
查看更多
登录 后发表回答