当运行终端命令ng server或ng serve——live-reload=true时,我得到了这个问题:

serve命令需要在Angular项目中运行,但是 找不到项目定义。


当前回答

确保你已经使用以下命令创建了angular应用,然后在创建的项目文件夹中运行ng serve。

ng new Project_Name

其他回答

我建议确认一下你是否在项目目录中。

我遇到了同样的错误。原因是新的angular cli更新使得angular-cli。Json是多余的,它被angular取代。json。我之前的Angular Cli版本是1.7.4,所以为了进行更改,我运行了下面的命令,它会为你完成转换:

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

当我们在错误的目录时,可能会发生此错误。所以使用CD命令来更改目录。 从上面的注释中,并不能很明显地看出具体是哪个命令给出的 这个错误。这个答案是基于你运行ng serve的假设 在根文件夹/实际项目文件夹之外。这就是给出错误的原因 Cli命令需要conf和build文件才能运行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

我也有同样的错误。所以,我首先去到根文件夹(文件夹包含angular。Json文件)然后

run "npm install" command(creating node modules),
then run "npm audit fix --force"
and then run "ng build",(building project)
and "ng serve"  (runnning project)

确保在项目中设置了新的angular版本配置。新的angular cli使用了angular。Json而不是。angular-cli。Json的配置。

遵循迁移指南。