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

I am using ionciv1, in the file ionic.config.json delete the angular type key and it worked correctly

example:

  {
  "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"
}

solved

     {
      "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"
    }
查看更多
老娘就宠你
3楼-- · 2020-01-24 11:24

As Usman said, i had a lot of trouble first time, I was following a tutorial. I had not set my directory to the project directory hence got this error.

I solved the issue by

  1. Setting the correct root directory to where my project was cd myproject
  2. Compile the app - ng serve

That was it.

查看更多
女痞
4楼-- · 2020-01-24 11:25

Solved. I was getting same issue on ubuntu 18.04.01 LTS. No above options worked as I was using NVM (Node Version manager.) Solution is
before creating project,use command
nvm use 10
(my node version was 10.15.0, so I used "nvm use 10")
It will show you output-
Now using node v10.15.0 (npm v6.4.1)
Versions will vary as per individual systems. then create new project.

查看更多
别忘想泡老子
5楼-- · 2020-01-24 11:27

if you have downloaded a project,do in the project

npm install

查看更多
再贱就再见
6楼-- · 2020-01-24 11:27

The same problem I came across, but I solved by following these steps of code.

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
查看更多
一夜七次
7楼-- · 2020-01-24 11:28

Make sure you have set the new angular version configuration in your project. The new angular cli uses angular.json and not .angular-cli.json for its configuration.

Follow migration guide.

查看更多
登录 后发表回答