Cannot find module 'internal/fs' after upgrading to node 7
First, open the console as administrator (or in the terminal with sudo
if it is a Linux) and:
npm cache clean
For npm 5 and later
npm cache clean --force
Edit:
For windows you might fail to clean the cache, so you can remove the cache manually by deleting all the following folder content:
C:\Users\<USER-NAME>\AppData\Roaming\npm-cache
Thanks "superwf", this case might happen for some, but I never had to do this (maybe because of my lowest security level?!).
End Edit.
Then go back to the normal console (not administrator or root), return to your project directory where the package.json is located, and then delete the node_modules
folder from your project, remove it completely, and then install node modules again inside your project folder:
npm install
You might need to update your modules before installing modules again. I recommend this, but be careful of breaking changes if there are any major version changes in your modules. This module npm-check-updates can help you to check the latest version and update them.
Also, you maybe need to install the latest global modules as well, check updates by:
ncu -g
or
npm outdated -g
If you're still stuck, you might need to remove the global node_modules
folder and reinstall what you want again.
Edit:
Yarn option: Some people ended with the same issues even with the cleanup procedures, actually you save your time a lot using Yarn.
Personally, I started to use yarn
instead of traditional npm i
, I can guarantee it is faster, and save your time, and your head from npm headaches.
In my case clearing the cache (OSX) did not work. I use n
to manage node which causes npm
to potentially be out of date. According to n docs you can update npm
with:
curl -0 -L https://npmjs.org/install.sh | sudo sh
In linux,when I update to node 7, this happened, "npm cache clean" does work.
In windows, npm cache clean also generate
Error: Cannot find module 'internal/fs'
Just remove
C:\Users[username]\AppData\Roaming\npm
C:\Users[username]\AppData\Roaming\npm-cache
solved
In my case clearing the cache did not work. Below was my initial state and how I resolved this:
node -v v7.4.0
npm -v 4.0.5
I resolved by doing the following and using n manager:
$ sudo n 6.9.1
$ sudo npm -g install npm@next
$ sudo n stable
Hope this helps!