How to fix npm "Cannot find module 'graceful-fs'" error
Problem:
When running any npm
command, you get a stacktrace similar to the following:
Error: Cannot find module 'graceful-fs'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:362:17)
at require (module.js:378:17)
at Object.<anonymous> (/usr/share/npm/lib/utils/ini.js:32:10)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:362:17)
Solution
Your npm
isn’t properly installed. Run
curl https://npmjs.org/install.sh | sudo bash
This reinstalls npm
on your computer, the issue should be resolved afterwards.
You might need to restart your shell after that for the changes to take effect.
In some cases even the installer fails because of the graceful-fs
error. In this case you might need to remove npm
using your distribution’s package manager first, e.g.
sudo apt-get remove npm
After this, try installing npm
again as shown above.