npm Cannot find module 'minimatch'

2020-07-11 06:32发布

问题:

I update my Node.js to 5.5.0. But it does not work when i use npm.

It reports error: Cannot find module 'minimatch'.

But Node.js version 4.2 is ok on my mac.

回答1:

Remove this folder /usr/local/lib/node_modules/npm/node_modules/rimraf/node_modules

rm -rf /usr/local/lib/node_modules/npm/node_modules/rimraf/node_modules


回答2:

This happened to me when I updated my node through the binary but also had a previous version installed through homebrew . The way I resolved this was, uninstalling node and npm completely and reinstalling using the binary found on their website .

sudo rm /usr/local/bin/npm
sudo rm /usr/local/share/man/man1/node.1
sudo rm /usr/local/lib/dtrace/node.d
sudo rm -rf ~/.npm
sudo rm -rf ~/.node-gyp
sudo rm /opt/local/bin/node
sudo rm /opt/local/include/node
sudo rm -rf /opt/local/lib/node_modules
brew unlink nodejs

and reinstall .



回答3:

I ran into probably the same exact problem as you.

I went from 4.2.3 LTS to 5.9, and all npm functionality ceased, always generating that error.

I had to do the following:

  1. Uninstall Node
  2. Save anything in your node installation folder that you may want to keep
  3. Completely delete the node installation
  4. Re-install 5.9

Everything was tip-top after that. I purged the folder after I noticed that there was the old 4.2.3 installer in the Installer directory. I didn't know what the ramifications of that were, but better safe than sorry.