(Don't replicate these steps till you read everything)
For me all mentioned solutions didn't work. Soo I went to /usr/lib
and run there
for package in `ls node_modules`; do sudo npm uninstall $package; done;
But it also removed the npm
package and only half of the packages (till it reached letter n).
So I tried to install node again by the node guide.
# Using Ubuntu
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt-get install -y nodejs
But it didn't install npm
again.
So I decided to reinstall whole node
sudo apt-get remove nodejs
And again install by the guide above.
Now is NPM again working but the global modules are still there. So I checked the content of the directory /usr/lib/node_modules
and seems the only important here is npm
. So I edited the command above to uninstall everything except npm
for package in $(ls node_modules); do if [ "$package" != "npm" ]; then sudo npm uninstall $package; fi; done;
It removed all modules what were not prefixed @
. Soo I extended the loop for subdirectories.
for package in $(ls node_modules); do if [ ${package:0:1} = \@ ]; then
for innerPackage in $(ls node_modules/${package}); do
sudo npm uninstall "$package/$innerPackage";
done;
fi; done;
My /usr/lib/node_modules
now contains only npm
and linked packages.