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

Please check whether you are inside your project folder or not and try the command ng serve again

I got the same error since I tried ng serve command outside of my project

Example :: let's say you have a project with name "Ecommerce" traverse into the folder and try the command ng serve open terminal cd Ecommerce ng serve

查看更多
Summer. ? 凉城
3楼-- · 2020-01-24 11:12

I faced the same issue when,

I had created new angular project using old angular-cli version (1.4.7) I then updated angular-cli using below commands (DO NOT DO THE BELOW TO UPDATE CLI)

  • npm uninstall -g @angular/cli
  • npm cache clean --force
  • npm install -g @angular/cli@latest

Now when I tried ng serve, i was getting same error like you

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

DO BELOW TO UPDATE CLI

ng update @angular/cli --migrate-only --from=1.4.7
查看更多
Anthone
4楼-- · 2020-01-24 11:15

I came across the same error. The reason is that new angular cli update makes angular-cli.json redundant, and it is replaced with angular.json instead. My previous Angular Cli version is 1.7.4, so to make the change, I ran the following command, it will make the conversion for you:

ng update @angular/cli --migrate-only --from=1.7.4
查看更多
再贱就再见
5楼-- · 2020-01-24 11:15

This error occurs when the project you are running is not an angular project. Though you have downloaded an angular project but have not installed all the dependencies thats why the ng serve command is not available to you.

Just navigate to the path where the project is stored and use the command

npm install

(Note - Node.js should be installed in your system and if you are using Angular 2 or above angular cli should also be installed in your system before you run this command. To check if the node.js is installed n your system 1) Open cmd (any path- as node should be globally installed in your system) 2) use command

node -v
npm -v

to get node and npm version)

One more important thing: The angular cli version won't make a difference if the version installed in your system is higher than the version required by the project. It will give a warning but you can ignore the warning.

查看更多
做自己的国王
6楼-- · 2020-01-24 11:16

I was also getting this issue and solved by running below command.

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

查看更多
爷、活的狠高调
7楼-- · 2020-01-24 11:17

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

Problem was missing angular.json files.

    ng update --all --force

Tested in Angular 7+

查看更多
登录 后发表回答