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

其他回答

任何问题在你的角度。Jason文件可能导致此错误。如果文件在你的目录中丢失了或者出现了错误。

我使用的是ionciv1,在文件ionic.config.json中删除angular类型键,它可以正常工作

例子:

  {
  "name": "nombre",
  "integrations": {
    "cordova": {}
  },
  "type": "angular", // delete
  "gulpStartupTasks": [
    "sass",
    "templatecache",
    "ng_annotate",
    "useref",
    "watch"
  ],
  "watchPatterns": [
    "www/**/*",
    "!www/lib/**/*"
  ],
  "browsers": [
    {
      "platform": "android",
      "browser": "crosswalk",
      "version": "12.41.296.5"
    }
  ],
  "id": "0.1"
}

解决了

     {
      "name": "nombre",
      "integrations": {
        "cordova": {}
      },
      "gulpStartupTasks": [
        "sass",
        "templatecache",
        "ng_annotate",
        "useref",
        "watch"
      ],
      "watchPatterns": [
        "www/**/*",
        "!www/lib/**/*"
      ],
      "browsers": [
        {
          "platform": "android",
          "browser": "crosswalk",
          "version": "12.41.296.5"
        }
      ],
      "id": "0.1"
    }

我遇到了同样的问题,但我通过以下代码步骤解决了这个问题。

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

切换到你的app文件夹,再次运行generate命令:

这解决了我的问题:

ng generate component nameComponent --module app.module