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?
220 Answers
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>5you may need to use cache verify instead. ($ npm cache verify)
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.
1Run 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 0Regular 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 CLIglobally
npm uninstall -g @angular/cli - Uninstall
Node.js&npmwith uninstaller - Remove every environment variables related to
Node.js&npm - Delete folders
C:\Users\<user>\AppData\Roaming\npmandC:\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 remove global reference
npm uninstall -g angular-cli npm cache clean 3Ran 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.
Angular cli has moved to @angular/cli, so as from the github readme,
sudo npm uninstall -g @angular/cli npm cache clean 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.
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.
To uninstall it globally just run below command:
npm uninstall -g @angular/cli Once it is done, clear your cache by running below command:
npm cache clean Now, to install the latset version of Angular, just run:
npm install -g @angular/cli@latest For details about Angular CLI, take a look at Angular introduction and CLI guide
1Installed 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:
This helped me a lot after one hour of desperate search, because I forgot, that I installed the CLI via yarn.
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 1I 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 use following command if you installed in globally,
npm uninstall -g angular-cli 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" } $ npm uninstall -g angular-cli $ npm cache clean $ npm install -g angular-cli 0Run this command
npm uninstall angular-cli 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 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 #### update npm to latest sudo npm install -g npm #### reinstall angular-cli sudo npm install -g @angular/cli 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