Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find module 'internal/fs' after upgrading to node 7

People also ask

Can not find module FS?

To solve the "Cannot find module fs or its corresponding type declarations" error, install the types for node by running the command npm i -D @types/node . You can then import fs with the following line of code import * as fs from 'fs' .

How do I fix a node module error?

If the error is not resolved, try to delete your node_modules and package-lock. json (not package. json ) files, re-run npm install and restart your IDE. Copied!

Where do I find npm?

In a web browser, navigate to https://nodejs.org/en/download/. Click the Windows Installer button to download the latest default version. At the time this article was written, version 10.16.0-x64 was the latest version. The Node.js installer includes the NPM package manager.


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!


I use the n tool to manage switching between node (and the bundled npm) versions.

To fix this error, I simply removed npm from the global space (macOS): sudo rm -rf /usr/local/lib/node_modules/npm

I then re-ran sudo n latest. This will re-install npm. When switching back to previous version of node just run sudo n 4.3.2.

To summarise:

> sudo rm -rf /usr/local/lib/node_modules/npm
> sudo n latest
> node --version
v7.7.1
> npm --version
4.1.2
> sudo n 4.3.2
> npm --version
2.14.12

The solution that worked for me was to

1) Delete node_modules/

sudo rm -R node_modules/ 

2) Re-run gulp

gulp


I'm on Windows 8.1 x64 , upgrading from v6 to v7. I got this issue on global installation I have many packages installed already, but every time I ran npm command, whether npm install, npm list,npm update etc. always return the same error

This step works for me:

  1. Clean npm cache manually by deleting npm-cache folder located at

C:\Users[usrname]\AppData\Roaming\

  1. Remove/rename npm folder in my NodeJS installation directory. In this case , I rename npm folder to npm-- in

C:\Program Files\nodejs\node_modules

  1. Re-install NodeJS v7

Everything works fine then