-1

When I used ng serve in my Angular project (in to correct place) its show this error in cmd.

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

I try this also

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

but this also not work for me. I tried also to delete node-module and reinstall, but not work. When I used npm start it work. Why? What is the problem?

My angular-cli.json code here

  "project": {
    "version": "1.0.0-beta.28.3",
    "name": "angular-src"
  },
  "apps": [
    {
      "root": "src",
      "outDir": "../public",
      "assets": [
        "assets",
        "favicon.ico"
      ],
      "index": "index.html",
      "main": "main.ts",
      "polyfills": "polyfills.ts",
      "test": "test.ts",
      "tsconfig": "tsconfig.json",
      "prefix": "app",
      "styles": [
        "styles.css"
      ],
      "scripts": [],
      "environments": {
        "source": "environments/environment.ts",
        "dev": "environments/environment.ts",
        "prod": "environments/environment.prod.ts"
      }
    }
  ],
  "e2e": {
    "protractor": {
      "config": "./protractor.conf.js"
    }
  },
  "lint": [
    {
      "files": "src/**/*.ts",
      "project": "src/tsconfig.json"
    },
    {
      "files": "e2e/**/*.ts",
      "project": "e2e/tsconfig.json"
    }
  ],
  "test": {
    "karma": {
      "config": "./karma.conf.js"
    }
  },
  "defaults": {
    "styleExt": "css",
    "prefixInterfaces": false,
    "inline": {
      "style": false,
      "template": false
    },
    "spec": {
      "class": false,
      "component": true,
      "directive": true,
      "module": false,
      "pipe": true,
      "service": true
    }
  }
}
Pavitran
  • 1
  • 1

2 Answers2

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

e.g.

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

getting ref from here https://github.com/angular/angular-cli/issues/12215#issuecomment-433593036

Jeba
  • 778
  • 1
  • 4
  • 13
0

Make sure that you are in the project directory in the terminal before running "ng serve".

Let's say your folder structure is as follows:

|-Documents
|---my_projects
|-----angular_project

Make sure that your terminal is in "angular_project" for example. i.e

username@PC_NAME:~/Documents/my_projects/angular_project$ ng serve
elonaire
  • 1,846
  • 1
  • 11
  • 17