129

I had the latest angular-cli installed globally and my project was building successfully.

While reading a suggested solution for another issue, (https://github.com/angular/angular-cli/issues/917) I uninstalled the global angular-cli and installed it as a dev-dependency.

That other issue wasn't solved so I uninstalled the dev-dependency and reinstalled angular-cli globally once again. Now when I try to do an ng build I'm getting the error:

You have to be inside an angular-cli project in order to use the build command

My angular-cli version did not change. Why isn't my project being recognised as an angular-cli project??

grim_i_am
  • 3,664
  • 5
  • 19
  • 19

20 Answers20

186

Same as John Pankowicz answer, but in my case I had to run

npm install -g @angular/cli@latest

for the versions to match.

Oswaldo Salazar
  • 1,968
  • 2
  • 8
  • 4
59
npm uninstall -g angular-cli @angular/cli
npm cache clean
npm install -g @angular/cli

use sudo on Mac/Linux.

Floern
  • 33,559
  • 24
  • 104
  • 119
Vinayaka
  • 591
  • 4
  • 2
  • npm ERR! As of npm@5, the npm cache self-heals from corruption issues and data extracted from the cache is guaranteed to be valid. If you want to make sure everything is consistent, use 'npm cache verify' instead. – obeliksz Feb 21 '18 at 07:47
  • If you face this issue: Could not find module "@angular-devkit/build-angular" from.... Then, it might be useful to run as well: npm install --save-dev @angular-devkit/build-angular – Mario Nov 07 '18 at 16:29
  • 1
    for 2nd step use --force e.g `npm cache clean --force` – Usman Saleh Jan 20 '20 at 06:57
  • This was the only thing that worked for me. Thanks! – Andrew Howard Jul 30 '20 at 15:35
53

Ok, found it.

package.json must contain a dependency to angular-cli.

When I uninstalled my local angular-cli, npm also removed the dependency entry.

grim_i_am
  • 3,664
  • 5
  • 19
  • 19
  • 8
    could you explain with more detail that part about the dependency? – Progs Feb 17 '17 at 19:14
  • Uninstalling angular-cli as a dev dependency, ie [ npm uninstall --save-dev angular-cli ] removed an entry from the packages.json "devDependencies": { "@angular/cli": "^1.0.0", "..." } and therefore you need to ensure that this entry is available under "devDependencies" or even "dependencies" if necessary – jabu.hlong May 15 '17 at 12:05
  • So what you did? what exactly you uninstalled? -g or --save? – Janatbek Orozaly Jul 10 '17 at 20:50
34

It worked in my case

sudo npm uninstall -g angular-cli @angular/cli
sudo npm cache clean --force
npm install npm@latest -g
sudo npm install -g @angular/cli
Diego Venâncio
  • 5,698
  • 2
  • 49
  • 68
Humble Freak
  • 459
  • 5
  • 10
26

I had the same error message. But the cause and solution are slightly different. When I ran "ng -v" it showed different versions for angular-cli (1.0.0-beta.28.3) and @angular/cli (1.0.0-beta.31). I re-ran:

npm install -g @angular/cli

Now both show a version of 1.0.0-beta.31. The error message is gone and "ng serve" now works. (Yes - it was @angular/cli that I re-installed and the angular-cli version was updated.)

John Pankowicz
  • 4,203
  • 2
  • 29
  • 47
  • Note that it takes a _very_ long time to refresh angular-cli, even an hour. In the middle of a time-critical task it may doom your project. – Tamás Polgár May 29 '17 at 21:14
  • For me I was trying npm install -g angular-cli, which is now deprecated. I had to npm install -g @angular/cli – Robbie Smith Nov 09 '17 at 21:34
15

Use npm install angular-cli --save-dev

Pedro Henrique
  • 151
  • 1
  • 4
15

Execute following commands step by step :

sudo npm uninstall -g angular-cli @angular/cli

sudo npm cache clean

npm install npm@latest -g

sudo npm install -g @angular/cli

npm rebuild node-sass --force
Prashant Pimpale
  • 10,349
  • 9
  • 44
  • 84
Mitesh Panchal
  • 151
  • 1
  • 4
11

This is what helped me when I found myself in the same problem:

npm uninstall -g angular-cli @angular/cli
npm cache clean --force
npm install -g @angular/cli@latest
Prashant Pimpale
  • 10,349
  • 9
  • 44
  • 84
sikaili99
  • 532
  • 6
  • 14
5
npm uninstall -g angular-cli
npm uninstall --save angular-cli
npm uninstall -g @angular/cli
npm uninstall --save @angular/cli
npm cache clean
npm install --save-dev @angular/cli@latest
jhoanna
  • 1,797
  • 25
  • 25
5

In my case (Mac OS X and previously used Angular 1.5 environment)

npm -g cache clean --force

npm cache clean --force

worked. (npm install -g @angular/cli@latest afterwards)

Alex Nevidomsky
  • 668
  • 7
  • 14
5

It works with npm install -g @angular/cli@latest for me.

UmaShankar
  • 221
  • 5
  • 14
2

This error comes when there's incompatibility between node version and angular/cli version. therefore use below command to update the cli version to latest

npm install -g @angular/cli@latest

Sunali Bandara
  • 402
  • 4
  • 6
2
npm uninstall -g angular-cli @angular/cli

npm cache clean --force

npm install -g @angular-cli/latest

I had tried similar commands and work for me but make sure you use them from the command prompt with administrator rights

giser_yugang
  • 6,058
  • 4
  • 21
  • 44
Onkar Nirhali
  • 216
  • 2
  • 8
1

I had the same issue - it turned out that i was using a deprecated angular-cli instead of @angular/cli. The latter was used by my dev team and it took me some time to notice that we were using a different versions of angular-cli.

Mac Keicam
  • 11
  • 1
1

Just include this in the package.json in devDependencies section

"angular-cli": "1.0.0-beta.25.5"

Not compulsory to install it if you have another vresion of cli installed globally.

I got this issue when I worked with angular2 & 4 at a time with different project. So angular4 - need angular-cli@latest and angular2 need angular-cli the above version.

Sanjay Kumar N S
  • 4,653
  • 4
  • 23
  • 38
1

I faced the same issue while running my project: I found out that if your project is using specific version of any thing in package.json find out that and install the specific version of that dependencies like for me, npm install @angular/cli@^4.0.0.

Rutvik Joshi
  • 97
  • 3
  • 13
1

It might be the problem with your version.

npm install -g @angular/cli@latest

The above run worked for me. Thanks!

Jaya Sundeep
  • 99
  • 1
  • 2
0

Dont forget of to use --force:

npm cache clean --force
Paul Roub
  • 36,322
  • 27
  • 84
  • 93
Diego Venâncio
  • 5,698
  • 2
  • 49
  • 68
0

I had the similar problem and nothing was working out but then I Followed below Steps and It worked for me. when I ran cmd as administrator it worked fine for me.

  1. First run the Command Prompt as administrator ans.

  2. Create the new project.

If it still doesn't create the project, remove the folder and all it's files, and then run ng new <project name> followed by ng serve.

If nothing works just uninstall node and every other file related to it and follow the steps above

Rob
  • 26,989
  • 16
  • 82
  • 98
0
npm uninstall -g angular-cli 

npm install -g @angular/cli

That's it!

enter image description here

vezunchik
  • 3,669
  • 3
  • 16
  • 25
  • 1
    Welcome to Stack Overflow! Please add code and data as text ([using code formatting](//stackoverflow.com/editing-help#code)), not images. Images: A) don't allow us to copy-&-paste the code/errors/data for testing; B) don't permit searching based on the code/error/data contents; and [many more reasons](//meta.stackoverflow.com/a/285557). In general, code/errors/data in text format >>>> code/errors/data as an image >> nothing. Images should only be used, in addition to text in code format, if having the image adds something significant that is not conveyed by just the text code/error/data. – double-beep May 22 '19 at 10:44
  • Thank you for welcoming me. I will take care of it next time. – Bhavya Shah Jul 31 '20 at 06:46