206

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.

Federico Grandi
  • 6,785
  • 5
  • 30
  • 50
Gurpreet Singh
  • 3,061
  • 5
  • 19
  • 36
  • 14
    Check if you have folder node_modules in the project folder, if not perform npm install – KEMBL Jan 07 '19 at 11:48
  • i already have node_modules folder. – Gurpreet Singh Jan 08 '19 at 06:33
  • I stumbled across this question when I had the same error message when trying to run "ng build". The answer for me was to run "npm run build" – cfranklin Feb 14 '20 at 18:55
  • 10
    I was in root directory, and getting this error :D. After `ng new project` I forgot to enter project directory. – Davut Gürbüz Jul 07 '20 at 08:43
  • 1
    I had the same problem as @DavutGürbüz , I was in the root directory and forgot to enter the project folder after creating angular project. – 27px Dec 21 '20 at 04:27

45 Answers45

255

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

Osama Rizwan
  • 615
  • 1
  • 7
  • 19
Lakhwinder Singh
  • 5,536
  • 5
  • 27
  • 52
  • 45
    It happens because new angular-cli depends uses angular.json instead of .angular-cli.json as project file, and your answer takes care of this conversion – Code Name Jack Nov 03 '18 at 19:05
  • 7
    Note: The `--from=1.7.4` represents the version being migrated from, so the `1.7.4` should be changed to the angular version you were formerly using (eg: `5.2.10`, `6.0.0`, etc). – cjn Nov 14 '18 at 03:58
  • 4
    ng update @angular/cli << this worked for me with an existing project from angular 6 to 7 – Abdullah Adeeb Nov 18 '18 at 04:25
  • 2
    I was on 1.2.4 and got the following error: `The specified command update is invalid. For available options, see ``ng help``.` I solved it by updating angular-cli to 1.7.4 and then following this answer. – ILikeFood Jan 09 '19 at 22:26
  • I have already updated version angular@cli (7.3.4) but still showing the same error. please help to resolve this. – Ajit Kumar Mar 04 '19 at 12:00
  • 1
    Thanks. Working for me when i upgraded angular from 4.4.7 to 7 – Pullat Junaid Apr 24 '19 at 11:38
  • 1
    You don't even know how much your post helped me! I've spend a whole day strrugling with this migration, all in vain but after I found your post and ran this command everything started to work perfectly. Thanks a lot! – Konstantin May 02 '19 at 08:09
  • Was getting this error when scaffolding a new project with VS2017 and .Net Core. Couldn't fix it, with this or other answers. Wound up deleting the project solution, updating Angular and re-scaffolded, worked fine. Was mistakenly thinking VS would install the latest version, but seems that it simply runs the `ng new ClientApp` command in the solution dir and the version is dependent on what you have already installed via CLI =/ – Zach A May 07 '19 at 01:07
  • How do we know which version we are on – VivekDev Feb 01 '20 at 13:44
  • 1
    @VivekDev you can check the version by this command `ng version`. Go to your project directory and run this command – Lakhwinder Singh Feb 03 '20 at 13:45
  • I successfully used this strategy to upgrade from Angular 5.2.5 to 10.0.1. All migration steps were carried out successfully. – MichaelHuelsen Jul 02 '20 at 17:49
140

make sure that you are running the command in the application root folder..

Me1o
  • 1,629
  • 1
  • 6
  • 8
54

if you have downloaded a project,do in the project

npm install

Muraletharan
  • 557
  • 4
  • 3
23

Finally, the command below fixed the issue for me!

ng update --all --force
Lesiak
  • 22,088
  • 2
  • 41
  • 65
Shahzeen shaikh
  • 230
  • 2
  • 4
  • I tried `ng update @angular/cli` didn't work but `ng update --all --force` worked as expected what would be the difference ? – k11k2 Apr 09 '19 at 12:03
  • '--all' functionality has been removed as updating multiple packages at once is not recommended. To update packages which don’t provide 'ng update' capabilities in your workspace 'package.json' use 'npm update' instead. – not2savvy Feb 14 '22 at 15:02
18

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+

Community
  • 1
  • 1
afeef
  • 4,396
  • 11
  • 35
  • 65
10

It was silly me but need to leave comment maybe I save someone else some hassle. Same message happens if you multitask and have multiple projects so some of project is nested inside project folder like projectFolder/subProject/projectOne so I was in projectFolder/subProject trying to run command ng serve.

Make sure you are in correct folder because same error will occur if you are in wrong folder and conf and build is missing!

StefaDesign
  • 929
  • 10
  • 19
6

It was happening in my existing project as I tried to update to latest node and npm packages:

  1. Uninstall global: npm uninstall -g angular-cli
  2. Reset Cache: npm cache clean or npm cache verify (for npm version > 5)
  3. Install latest: npm install -g @angular/cli@latest
amrendra
  • 345
  • 2
  • 12
  • The only issue with uninstalling and installing npm is that it may break 3rd party libraries that are installed. Another work around would be to just copy paste package.json and package-lock.json from repo and then do npm-update. – Haseeb Khan May 10 '22 at 09:30
5

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.

Lasithe
  • 1,916
  • 1
  • 15
  • 20
3

In your Package Manager Console run the command

PM> cd NameofApp 

then you can try to run the command there.For instance

PM > ng generate component Home
3

This happens when you try to run the Angular command "ng s" or "ng serve" on the other folder instead of the root folder of the Angular application.

Also upgrade the Angular using the following command:

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

This will sort it out.

סטנלי גרונן
  • 2,917
  • 23
  • 46
  • 68
3

This error may be occur when we are in wrong directory.so use cd command to change your directory. It's not very evident from the above comment that which specific command is giving this error so this answer is based on assumption that you are running ng serve outside the root folder/actual project folder. That's why it's giving error because cli commands require conf & build files to run the 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
Rin and Len
  • 447
  • 6
  • 22
3

to reinstall back freshly the application is way better rather than update or editing some config that is not recognize by npm due to missing config or we are not really sure what is wrong.

I choose @Tinu solution is work

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

just made backup for our current source code and put it back to new angular project that be created.

edan
  • 68
  • 8
3

Change to your app folder, and run generate command again:

enter image description here

live-love
  • 48,840
  • 22
  • 240
  • 204
3

This error usually can be traced back to an update to our global or local CLI runtime. To check if this is the problem, we need to review the package.json file. There, we should look for the @angular/cli dependency. This should indicate the CLI version that was used to create our project. Lets make a note of this value, as we need to use it to migrate our project later on.

We should now compare to the current CLI runtime by entering the following command on the terminal window.

ng v

output of ng v

If you get error An unhandled exception occurred: ENOENT: no such file or directory, scandir '~/your-app/node_modules', then you forgot to run npm install

The console should display the current CLI version. If the versions are different, we need to migrate the project to the new CLI version by running the command below. Note that the from version parameter should set to the value found for the @angular/cli setting.

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

We should now take a look at our project and should notice changes to the CLI dependency version in the package.json file. Also depending on your CLI version, the .angular-cli.json file is deleted, and a new angular.json file is created. This is the project file that the new CLI is looking for and thus the source of the error of no project found. By adding this file, we should be able to be back on track on run our project again.

We should be able to enter the following command and the project should be loading fine.

ng server

Thanks to ozkary

Norman Edance
  • 352
  • 4
  • 14
2

I had the same issue with Angular7 because we need to go the root folder before run your application. Go to the root folder of your app and run the command. It works perfectly for me.

Chamila Maddumage
  • 3,304
  • 2
  • 32
  • 43
2

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
2

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.

Utkarsh Joshi
  • 141
  • 1
  • 3
  • haha my case is exactly like that, npm install worked for me, it was the dependencies that made noise – Gopal Nov 09 '20 at 08:01
2

Tried all the above But for me it was solved by

npm start

viveksuggu
  • 737
  • 2
  • 7
  • 12
  • this should be in the comment section – Pardeep Sep 20 '19 at 07:07
  • @Pardeep I have tried all the above answer but npm start worked me. so it will helpful for the other developer. if it is made as eye catching answer rather than keeping in the comments – viveksuggu Sep 20 '19 at 09:03
2

Make sure you have created angular App using below command, then running ng serve in created Project folder.

ng new Project_Name
sid7747
  • 690
  • 7
  • 15
2

This project doesn't use the angular cli, it uses webpack directly. To start run the command

npm start

Nishant Shah
  • 2,022
  • 22
  • 20
1

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
Vinayak Savale
  • 538
  • 6
  • 7
1

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
Vino
  • 2,807
  • 1
  • 26
  • 22
1

In my case, I forgot to change my directory, so just after running the command :

ng new AngularProject

execute another command :

cd AngularProject

and ng serve worked for me.

Usman Khalid
  • 3,032
  • 9
  • 41
  • 66
1

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.

kk.
  • 3,747
  • 12
  • 36
  • 67
Maxwell Fundi
  • 11
  • 1
  • 1
1

This happens because we are hitting ng serve command in some other path.This can be solved by hitting ng serve or npm start command on the path where exactly the our project resides(take path until the folder which contains src,node_modules,etc.)

F:\project\AngularDemo\AngularDemoapp> ng serve

1

I would suggest to confirm if you are in the directory of the project.

RPDF
  • 76
  • 8
1

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

It happened to me that I was trying to execute the ng serve command in a project created with Ruby on Rails. In other words, I had to run the rails -s command for Ruby on Rails. I got confused because Angular was built into Ruby on Rails so I had to run the rails -s command to start my project's local server and it worked without a problem.

Nube Colectiva
  • 147
  • 2
  • 7
1

I also had this same error. So, i first went to root folder(folder containing angular.json file) and then

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)
Brijesh Ray
  • 779
  • 8
  • 15
1

this 3 commands helped me npm install --force npm audit fix --force npm start

manishsingh2061
  • 521
  • 1
  • 6
  • 13
0

Also make sure if you are running ng serve that you stop it first...

dirtyw0lf
  • 1,899
  • 5
  • 35
  • 63
0

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.

0

You can update the angular with command 'ng update --all'. It will take time but make sure your all components are up to date.

0

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

0

This fixed my problem:

ng generate component nameComponent --module app.module
cs95
  • 379,657
  • 97
  • 704
  • 746
PoussinDev
  • 21
  • 4
0

Happened to me when didn't install angular core:

Angular CLI: 9.0.0-rc.0
Node: 11.12.0
OS: darwin x64
Angular: undefined
...

So I run

npm i @angular/core

which gave me ng -v

Angular CLI: 9.0.0-rc.0
Node: 11.12.0
OS: darwin x64
Angular: 8.2.13
... core

Then I run

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

removed node_modules

npm install
cd <project name>
ng serve

And it worked!

** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ ** ℹ 「wdm」: Compiled successfully.

mariano
  • 84
  • 3
0

I was having the same problem with VS Code, turns out that enabling detection of Angular Icons fixes the problem

Joseph Waweru
  • 1,680
  • 18
  • 14
0

Even ng update --all --force doesn't work?

It might be simply when you're performing Angular upgrade from version when .angular-cli.json (for example Angular 4) has been used to one of the newer versions having angular.json. In that case you might need to delete the .angular-cli.json and replace with equivalent metadata angular.json. After that, you'll be able to perform update from one command or step-by-step.

Daniel Danielecki
  • 8,508
  • 6
  • 68
  • 94
0

Any issue in your angular.jason file can cause this error. So if the file is missing in your directory or it has an error that can happen.

NKZ
  • 11
  • 2
0

Try --> npx ng serve

I've got this same error running ng serve and I've fixed it running npx ng serve

0

I had started off with a theme sample project base. It's angular.json

 "projects": {
    "<project name>": {
      "projectType": "application",
      "schematics": {
        "@schematics/angular:component": {
    ...

It also has

 "defaultProject": "<project name>",
  "cli": {
    "analytics": false
  }

Matching the project name with this solved my problem on Angular 13.

Ishwara Bhat
  • 186
  • 1
  • 9
0

I made a mistake of running ng server in the parent directory of the Angular application, OP got the answer but if anyone is searching the answer might want to cd into the application directory too.

Rishabh
  • 51
  • 1
  • 7
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 23 '22 at 16:22
  • This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). To get notified when this question gets new answers, you can [follow this question](https://meta.stackexchange.com/q/345661). Once you have enough [reputation](https://stackoverflow.com/help/whats-reputation), you can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question. - [From Review](/review/late-answers/31356476) – J.Salas Mar 25 '22 at 11:16
0

Just go on to your project name in vs code and right click on that project name there you'll find "Open in integrated terminal" there you type --ng serve-- that how it helps me and fixed my problem as well. Which happened because of incorrect path!

Naveen
  • 43
  • 6
0

Issue is with your base or folder paths Open your command prompt or terminal and run ng new command to create the new Angular application.

D:\Angular Applications>ng new test-app It will create a new folder called test-app and that folder contains our Angular source code.

Now D:\Angular Applications\test-app is our Angular project root directory.

You have to navigate to project root directory and then you have to run ng serve.

D:\Angular Applications> cd test-app

D:\Angular Applications\test-app>ng serve

Its should works

-1

it kept giving me the same errors. i tried all the commands on this page with no avail. i turned the computer off and on. it worked for me.

Gamal Last
  • 27
  • 1
  • 4
  • 2
    `i tried all the commands on this page` and then you rebooted. Which means at least one of these solutions worked, but now you don't know which one. The reboot itself isn't likely to be the sole solution. – Eric Aya Aug 14 '21 at 11:44