Reputation: 135
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.
Upvotes: 6
Views: 19029
Reputation: 403
I had a similar issue and reinstalling works for me. this straightforward approach works fine for me. founded here
First, remove old staff
sudo rm -rf /usr/local/bin/npm /usr/local/share/man/man1/node* ~/.npm
sudo rm -rf /usr/local/lib/node*
sudo rm -rf /usr/local/bin/node*
sudo rm -rf /usr/local/include/node*
sudo apt-get purge nodejs npm
sudo apt autoremove
then, Download the latest tar.xz NodeJS file from official site
tar -xf node-v#.#.#-linux-x64.tar.xz
sudo mv node-v#.#.#-linux-x64/bin/* /usr/local/bin/
sudo mv node-v#.#.#-linux-x64/lib/node_modules/ /usr/local/lib/
Where #.#.# is the version you downloaded.
finally, Verify installation using
node -v
npm -v
Upvotes: 15
Reputation: 861
Try
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
apt-get update
apt-get install nodejs
You might also want to check out the answers here: Npm install cannot find module 'semver'
Upvotes: 11