I am using ubuntu 19.04.
I am getting following error, when trying to do anything with npm
internal/modules/cjs/loader.js:638
throw err;
^
Error: Cannot find module 'semver'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (/usr/share/npm/lib/utils/unsupported.js:2:14)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
I have tried to apply different solutions from SO, but unfortunately they have not worked.
It started happening after reinstalling NPM because of some errors I unfortunately cannot recreate.
What I have tried
sudo apt purge nodejs
sudo apt autoremove
after these two steps, npm is uninstalled.
npm -v
bash: /usr/bin/npm: No such file or directory
I proceed to
sudo apt install nodejs
However the error occurs even after I have purged the files
User@User:/$ node -v
v10.16.3
User@User:/$ npm -v
internal/modules/cjs/loader.js:638
throw err;
^
Error: Cannot find module 'semver'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (/usr/share/npm/lib/utils/unsupported.js:2:14)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
I have also tried following
sudo apt purge npm
sudo apt purge nodejs
sudo apt autoremove
sudo apt install npm
sudo apt install nodejs
sudo rm -rf /usr/local/lib/node_modules
sudo rm -rf ~/.npm
brew uninstall --force node
brew install node
It still yields the same error. The global files should be uninstalled with both of these approaches.
To be certain I have searched the computer with and deleted anything if it looked like something relevant to node or npm.
sudo find / -type f -name "node"
sudo find / -type f -name "node_modules"
sudo find / -type f -name "npm"
It is if something is carried on through the purging, perhaps some files communication with NPM yielding the error.