177

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?

2

20 Answers 20

461

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)
14
  • 16
    Please note that Angular CLI has moved to @angular/cli: [sudo] npm install -g @angular/cli Commented Apr 4, 2017 at 15:17
  • 5
    npm cache clean is superseded by npm cache verfy so it seems Commented Jul 10, 2017 at 9: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
    Commented Dec 19, 2017 at 11:24
  • 1
    how to uninstall latest version angular cli and install angular cli 1.6.1 Commented Jan 21, 2018 at 13:28
  • 3
    @NaomG npm version > 5 doesn't need you to clean cache.. but still if you need it run npm cache clean --force Commented Mar 29, 2018 at 7:04
45

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.

1
38

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
1
  • The right answer, i only suggest add if you have a nvm, first nvm deactivate, this command only apply in the current shell, i have problem when try execute the uninstall the console response 'up to date in 4.2 sec' Commented Jul 14 at 23:00
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
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.

8

remove global reference

npm uninstall -g angular-cli
npm cache clean
3
  • 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) Commented Sep 19, 2016 at 6:28
  • This is very generic error it could be anything, missing dependency or wrong configuration. Better to ask this on github.com/angular/angular.js/issues . BTW above is the way to uninstall angular.
    – A.T.
    Commented Sep 19, 2016 at 6:50
  • add '--force' to the end without the single quotes.
    – Dale
    Commented Jun 29, 2018 at 22:59
7

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
1
  • 1
    For me, I found @angular folder at /usr/local/lib/node_modules/
    – King
    Commented Jun 5, 2022 at 19:25
5

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

sudo npm uninstall -g @angular/cli
npm cache clean
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.

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.

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.

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
0

use following command if you installed in globally,

 npm uninstall -g angular-cli
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"
  }
0
 $ npm uninstall -g angular-cli 
 $ npm cache clean 
 $ npm install -g angular-cli
0
0

Run this command

npm uninstall angular-cli
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
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
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.

1
  • 1
    using npm uninstall -g angular-clI is the better option. Commented Apr 18, 2017 at 10:41

Not the answer you're looking for? Browse other questions tagged or ask your own question.