当运行终端命令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)

其他回答

当我们在错误的目录时,可能会发生此错误。所以使用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版本(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

我也得到了这个问题,并通过运行下面的命令来解决。

ng update @angular/cli --migrate-only --from=<WhateverVersionYouAreCurrentlyOn>

e.g.

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

从这里获取裁判

确保您在应用程序根文件夹中运行该命令。

发生这种情况是因为我们在其他路径上执行了ng serve命令。这可以通过在我们的项目所在的路径上敲击ng serve或npm start命令来解决(取路径直到包含src,node_modules等的文件夹为止)。

F:\project\AngularDemo\AngularDemoapp> of serve