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

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


当前回答

我也有同样的错误。所以,我首先去到根文件夹(文件夹包含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)

其他回答

只要继续在vs code中找到你的项目名称,右键单击该项目名称,你会发现“在集成终端中打开”,在那里输入-ng serve-这是如何帮助我和解决我的问题的。这是因为错误的路径!

我犯了一个错误,在Angular应用程序的父目录下运行ng server, OP得到了答案,但如果有人正在搜索答案,可能也想cd到应用程序目录中。

当我们在错误的目录时,可能会发生此错误。所以使用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 cli更新使得angular-cli。Json是多余的,它被angular取代。json。我之前的Angular Cli版本是1.7.4,所以为了进行更改,我运行了下面的命令,它会为你完成转换:

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

我也遇到过同样的问题,

我用旧的angular-cli版本(1.4.7)创建了一个新的angular项目 然后我用下面的命令更新了angular-cli(不要用下面的命令更新CLI)

NPM卸载@angular/cli NPM缓存清理——force 安装-g @angular/cli@latest

当我发球的时候,我也会像你一样犯同样的错误

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

如何更新cli

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