When I upgraded my node to 7+ and npm to 4+ I started facing problem while running 'npm install'. It was throwing error ‘Cannot find module 'internal/fs'’. I googled a lot and found out that my node/npm versions were unsupportive of certain modules. I tried to change the version but nothing happened. Then i tried running ‘Gulp’ which I was using in my app for module bundling. To my surprise it said ‘zsh: command not found: gulp’.
Now I thought, the only way to get rid of these problems to re-install node/npm again. I did ‘brew uninstall node’ and still node -v -> v7.4.0 This was frustrating!!!
I googled to see if there is another one line code by Node to uninstall it, but could’nt find anything. Then I read somewhere on the web that I have to remove node from all possible places and only then I will be assured that its been uninstalled.
Below are the steps that you should follow to uninstall node/npm and then re-install it.
sudo rm -rf node
sudo rm -rf node_modules
sudo rm -rf node
sudo rm -rf node_modules
Now check your home directory and remove node, node_modules or ay node executables from anywhere you find it. Check local, lib, include, bin folder. ANYWHERE you find it!
sudo rm -rf /usr/local/bin/npm
If you have installed node via brew(as I didn’t remember if I had used brew to install node, therefore to be on the safer side I ran this command as well), then run
Brew uninstall node
sudo rm -rf /usr/local/share/man/man1/node.1
sudo rm -rf /usr/local/lib/dtrace/node.d
sudo rm -rf ~/.npm
This removes all node/npm from your system, now you can reinstall node. I installed from the node website by downloading the package. You can also install using brew - brew install node.
You can check the version of node and npm installed by
node -v
npm -v
Now ‘npm install’ ran smoothly and after installing gulp globally I was able to work again.