168

When I try to create a new project with Angular CLI, with:

ng n app

I get this error:

fs.js:640 return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode); ^ TypeError: path must be a string or Buffer at TypeError (native)

How can I upgrade or uninstall Angular CLI?

veben
  • 19,637
  • 14
  • 60
  • 80
RohanArihant
  • 2,560
  • 4
  • 19
  • 29

20 Answers20

445

Using following commands to uninstall :

npm uninstall -g @angular/cli
npm cache clean --force

To verify: ng --version /* You will get the error message, then u have uninstalled */

Using following commands to re-install :

npm install -g @angular/cli

Notes : - Using --force for clean all the caches - On Windows run this using administrator - On Mac use sudo ($ sudo <command>)

  • If you are using npm>5 you may need to use cache verify instead. ($ npm cache verify)
Aathil Ahamed
  • 460
  • 4
  • 16
Santosh Pillai
  • 8,169
  • 1
  • 31
  • 27
  • 16
    Please note that Angular CLI has moved to @angular/cli: [sudo] npm install -g @angular/cli – Osmund Francis Apr 04 '17 at 15:17
  • 5
    npm cache clean is superseded by npm cache verfy so it seems – Arnd Brugman Jul 10 '17 at 09:16
  • 3
    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. – NoamG Dec 19 '17 at 11:24
  • how to uninstall latest version angular cli and install angular cli 1.6.1 – Ayyappa amara Jan 21 '18 at 13:28
  • [Here](https://medium.com/@enirate/how-to-update-to-angulars-latest-cli-version-angular-cli-c7b1dce36476) is another **solution**. – Shaiju T Feb 20 '18 at 09:11
  • 3
    @NaomG npm version > 5 doesn't need you to clean cache.. but still if you need it run `npm cache clean --force` – Ashish Yadav Mar 29 '18 at 07:04
  • I have installed cli latest but my project was with older version and now everything is crashed, is there any solution to install any older cli ? –  Jun 23 '18 at 21:56
  • Do NOT use sudo with npm: https://medium.com/@ExplosionPills/dont-use-sudo-with-npm-5711d2726aa3 – Gustavo Piucco Jul 16 '18 at 00:20
  • use `npm cache verify` instead of `npm cache clean` – Dev M Aug 10 '18 at 09:53
  • If you follow the above and `ng v` gives the old version still, you can run `npm link @angular/cli` (this links to the latest install on Mac at least). – jsaven Sep 26 '19 at 12:14
  • Once you uninstalled angular check the version of angular then you can easily identify angular completely deleted or not .Type the following command(these are usual commands to check angular version and some other details). `ng version` or `ng --v` or `ng -v` or `ng -version` if you type above code you should get an error said like that`not recognized command` – AHAMED AAQIB Jun 24 '20 at 06:52
  • if npm cache clean --force does not clean the cache, then we've to manually dele the folder "npm-cache" from "C:\Users\[Admin]\AppData\Roaming" – agileDev May 06 '21 at 04:24
  • should I use administrator right when reinstalling it? – Agung Sudrajat Aug 20 '21 at 06:42
  • Does it matter what folder you are in for this command? Or is it pervasive on your system. – Micah Dec 09 '21 at 16:31
44

None of the above solutions alone worked for me. On Windows 7 this worked:

Install Rapid Environment Editor and remove any entries for node, npm, angular-cli or @angular/cli

Uninstall node.js and reinstall. Run Rapid Environment Editor again and make sure node.js and npm are in your System or User path. Uninstall any existing ng versions with:

npm uninstall -g angular-cli

npm uninstall -g @angular/cli

npm cache clean

Delete the C:\Users\YOU\AppData\Roaming\npm\node_modules\@angular folder.

Reboot, then, finally, run:

npm install -g @angular/cli

Then hold your breath and run ng -v. If you're lucky, you'll get some love. Hold your breath henceforward every time you run the ng command, because 'command not found' has magically reappeared for me several times after ng was running fine and I thought the problem was solved.

M.A.K. Ripon
  • 2,070
  • 3
  • 29
  • 47
VanAlbert
  • 2,299
  • 1
  • 21
  • 17
35

Run the following commands to get the very latest of angular

npm uninstall -g @angular/cli
npm cache verify
npm install -g @angular/cli@latest
ng version
Stanley Mohlala
  • 6,816
  • 1
  • 11
  • 20
13

Regular solution, that does not work always:

npm uninstall -g @angular/cli
npm cache verify
npm install -g @angular/cli

Other more drastic solution:

  • Uninstall Angular CLI globally
npm uninstall -g @angular/cli
  • Uninstall Node.js & npm with uninstaller
  • Remove every environment variables related to Node.js & npm
  • Delete folders C:\Users\<user>\AppData\Roaming\npm and C:\Users\<user>\AppData\Roaming\npm-cache
  • Verify these commands are ko:
ng version
npm -v
node -v
npm install -g @angular/cli
  • Finally, check your global Angular CLI version:
ng version
veben
  • 19,637
  • 14
  • 60
  • 80
10

Ran into this recently myself on mac, had to remove the ng folder from /usr/local/bin. Was so long ago that I installed the Angular CLI, I'm not entirely sure how I installed it originally.

jassok
  • 421
  • 3
  • 12
6

remove global reference

npm uninstall -g angular-cli
npm cache clean
A.T.
  • 24,694
  • 8
  • 47
  • 65
  • but error is same. Do anyone have any solution for that fs.js:640 return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode); ^ TypeError: path must be a string or Buffer at TypeError (native) at Object.fs.openSync (fs.js:640:18) at Object.fs.readFileSync (fs.js:508:33) – RohanArihant Sep 19 '16 at 06:28
  • This is very generic error it could be anything, missing dependency or wrong configuration. Better to ask this on https://github.com/angular/angular.js/issues . BTW above is the way to uninstall angular. – A.T. Sep 19 '16 at 06:50
  • add '--force' to the end without the single quotes. – Dale Jun 29 '18 at 22:59
5

Angular cli has moved to @angular/cli, so as from the github readme,

sudo npm uninstall -g @angular/cli
npm cache clean
All Іѕ Vаиітy
  • 24,861
  • 16
  • 87
  • 111
5

I tried all the above things, and still ng as sticking around globally. So in powershell I ran Get-Command ng, and then it became clear what my problem was. I was using yarn heavily in the past, and all the old angular cli packages were also installed globally in the yarn cache location. I deleted my yarn cache for good measure, but probably could have just updated the global angular cli via yarn. In any case, I hope this helps remind some of you that if you use yarn, then global commands like ng can also live in another path than where npm puts them.

Rafe
  • 8,467
  • 8
  • 47
  • 67
3

Well inline with many answers above even I had the issue where I wasn't able to create a new-app with angular cli 9.1.0 on Mac OS 10.15.3 . My issue was resolved by uninstalling the angular cli, cleaning the cache and re-installing the angular cli.

npm uninstall -g @angular/cli

Verify installation status with ng --version

npm cache verify
npm install -g @angular/cli

Try creating new app with ng new my-app now to see if the above helps.

3

If nothing works for, you can also check your globally installed node modules like so:

cd /usr/local/lib/node_modules/npm/node_modules

Then remove the @angular folder:

rm -R @angular

And reinstall the angular-cli by running:

npm install -g @angular/cli
timoblume
  • 76
  • 3
2

Installed with yarn

If you added the angular cli with yarn, you can only remove (and therefor update) it the same way. See the short but great answer here: https://stackoverflow.com/a/56192531/13226740

This helped me a lot after one hour of desperate search, because I forgot, that I installed the CLI via yarn.

Tino
  • 646
  • 2
  • 9
  • 15
1

I always use the following commands before upgrading to latest . If it is for Ubuntu prefix : 'sudo'

npm uninstall -g angular-cli
npm cache clean
npm install -g angular-cli@latest
Yashwanth Kata
  • 817
  • 8
  • 21
0

use following command if you installed in globally,

 npm uninstall -g angular-cli
Ajith K P
  • 398
  • 3
  • 12
0

Run this command

npm uninstall angular-cli
RavinderSingh13
  • 130,504
  • 14
  • 57
  • 93
0

Not the answer for your question, but the answer to the problem you mentioned:

It looks like you have wrong configuragion file for the angular-cli version you are using.

In angular-cli.json file, try to change the following:

from:

  "environmentSource": "environments/environment.ts",
  "environments": {
    "dev": "environments/environment.ts",
    "prod": "environments/environment.prod.ts"
  }

to:

  "environments": {
    "source": "environments/environment.ts",
    "dev": "environments/environment.ts",
    "prod": "environments/environment.prod.ts"
  }
Gal Tamir
  • 77
  • 6
0
 $ npm uninstall -g angular-cli 
 $ npm cache clean 
 $ npm install -g angular-cli
Lekens
  • 1,823
  • 17
  • 31
0

I got similar issue while I was creating a new angular app. The problem for me was due to npm 7 and I just downgraded npm.

npm install -g npm@6

If we need to uninstall or upgrade cli, we can use these commands

npm uninstall -g @angular/cli
npm cache clean --force

then reinstall using the command

npm install -g @angular/cli
Rohith V
  • 1,089
  • 1
  • 9
  • 23
0

For the error I was facing:

ERR! code ENOTEMPTY npm ERR! syscall rename npm ERR! path /usr/local/lib/node_modules/@angular/cli npm ERR! dest /usr/local/lib/node_modules/@angular/.cli-G39XYeT9 npm ERR! errno -66 npm ERR! ENOTEMPTY: directory not empty, rename '/usr/local/lib/node_modules/@angular/cli' -> '/usr/local/lib/node_modules/@angular/.cli-G39XYeT9'

I used the following steps and it worked:

#### uninstalling globally installed libs
sudo npm uninstall -g @angular/cli
#### uninstall other libs
sudo npm uninstall -g

#### uninstalling node
sudo rm -rf /usr/local/{lib/node{,/.npm,_modules},bin,share/man}/{npm*,node*,man1/node*}
rm -rf /Users/[homedir]/.npm

#### reinstall node
https://nodejs.org/en/download/

#### update npm to latest
sudo npm install -g npm

#### reinstall angular-cli
sudo npm install -g @angular/cli
ASANIAN
  • 372
  • 2
  • 8
0

Im my case, after trying everything: I was using a proxy internet connection. I was using my cell phone to repeat the signal. Believe or not, this was the problem, after I have tried essentiallly all solutions online. Found somewhere something about proxy, and remember I am using proxy. Just to maybe save the life of somebody else, it is money!

-2

Simplest workaround to continue working in your project is comment line 25 of node_modules/angular-cli/bin/ng:

// Version.assertPostWebpackVersion();

Until it is fixed properly.

Emile Bergeron
  • 17,074
  • 5
  • 83
  • 129
Vadym
  • 9