node icon indicating copy to clipboard operation
node copied to clipboard

Error: Cannot find module 'internal/fs' when npm install on mac

Open shufanshijie opened this issue 10 years ago • 95 comments

5 verbose stack Error: Cannot find module 'internal/fs'
5 verbose stack     at Function.Module._resolveFilename (module.js:472:15)
5 verbose stack     at Function.Module._load (module.js:420:25)
5 verbose stack     at Module.require (module.js:500:17)
5 verbose stack     at require (internal/module.js:20:19)
5 verbose stack     at evalmachine.<anonymous>:17:20
5 verbose stack     at Object.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/cmd-shim/node_modules/graceful-fs/fs.js:11:1)
5 verbose stack     at Module._compile (module.js:573:32)
5 verbose stack     at Object.Module._extensions..js (module.js:582:10)
5 verbose stack     at Module.load (module.js:490:32)
5 verbose stack     at tryModuleLoad (module.js:449:12)
6 verbose cwd /Users/huweiqing
7 error Darwin 14.5.0
8 error argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "iconv-lite"
9 error node v7.0.0
10 error npm  v3.10.8
11 error code MODULE_NOT_FOUND
12 error Cannot find module 'internal/fs'

shufanshijie avatar Oct 31 '16 13:10 shufanshijie

downgrade a stable version of a package is not a fix. the software need to be fixed to works with last packages.

roastercode avatar Nov 19 '16 14:11 roastercode

I just followed shufanshijie instructions and this worked out fine. Thanks.

OrganicChem avatar Nov 19 '16 17:11 OrganicChem

I installed node v7.1.0 into a local user directory ~/local/bin on my Mac OS X El Capitan machine (10.11.6), and received this error. I have been installing node from source code since the version 0.10 days, but don't actually write much application code with it.

I followed Fishrock123's advice in this way:

cd ~/local/lib $ rm -rf node_modules/npm

and reinstalled node from the source code directory where I had already done the compile:

make install

...and that resolved my issue.

BobCochran avatar Nov 20 '16 00:11 BobCochran

I installed Node via Homebrew, but not npm, so I could properly separate Node packages from the Homebrew installation. Recently Homebrew updated Node to 7.0.0 and today I run into this problem too. I hadn't noticed it before (I rarely use Node stuff ;) ).

Downgrading Node wasn't an option as I can neither upgrade or downgrade my Homebrew installation anymore since they block root usage these days for some unvalidated security paranoia reason.

Luckily fixing npm was more easy, than I was expecting after reading this (and some other) issues threads here on GitHub.

$ npm ls --global graceful-fs
/usr/local/node/lib
└─┬ [email protected]
  ├─┬ [email protected]
  │ └── [email protected] 
  └── [email protected] 

As you can see I had an old and an up-to-date graceful-fs in my installation. So I just renamed the old one and then run an npm "update":

$ cd /usr/local/node/lib/node_modules/npm/node_modules/cmd-shim/node_modules
$ sudo mv graceful-fs graceful-fs,bak
Password:
$ sudo npm install npm -g

This seemed to fix the issue for me:

$ npm ls --global graceful-fs
/usr/local/node/lib
└─┬ [email protected]
  └── [email protected] 

Just sharing this information here in case it might be helpful for someone else running into this problem.

the-real-tokai avatar Nov 29 '16 13:11 the-real-tokai

@the-real-tokai fixed this issue, removing and reinstalling graceful-fs was the solution.

etjossem avatar Dec 09 '16 18:12 etjossem

I have this problem too, but this : sudo apt-get remove cordova-cli sudo npm install cordova Solve my problem :) !

6be709c0 avatar Dec 13 '16 07:12 6be709c0

I had same problem. Initially had node installed with brew and then moved to nvm. Here is the error:

➜ npm install -g bower
/Users/florian/.nvm/versions/node/v7.2.1/bin/bower -> /Users/florian/.nvm/versions/node/v7.2.1/lib/node_modules/bower/bin/bower
/Users/florian/.nvm/versions/node/v7.2.1/lib
└── [email protected]

➜ bower --version
module.js:472
    throw err;
    ^

Error: Cannot find module 'internal/fs'
    at Function.Module._resolveFilename (module.js:470:15)
    at Function.Module._load (module.js:418:25)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at evalmachine.<anonymous>:17:20
    at Object.<anonymous> (/usr/local/lib/node_modules/bower/node_modules/graceful-fs/fs.js:11:1)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)

From the stacktrace you can see it is still referencing modules from the wrong place /usr/local/lib/node_modules instead of ~/.nvm/versions/node/v7.2.1/lib/node_modules.

My fix was:

  • brew uninstall node
  • rm -rf /usr/local/lib/node_modules

sey avatar Dec 17 '16 11:12 sey

I had the same problem with bower after upgrading to node 7.0.0 (installing with node official dmg . after removing bower and re-installing (npm remove -g bower). all worked fine.

osadan avatar Dec 19 '16 12:12 osadan

I had the same problem. What worked for me was uninstalling and reinstalling cordova.

My fix was:

npm cache clean
npm uninstall cordova -g
npm install cordova -g

jacuchilla avatar Dec 23 '16 04:12 jacuchilla

seems to happen to me after i use yarn once.

matthewmueller avatar Dec 23 '16 05:12 matthewmueller

I faced the issue while doing a bower init. cd /usr/local/lib/node_modules/bower/lib/node_modules/ rm -rf graceful-fs npm install bower -g

and then it works just fine.

ghost avatar Dec 24 '16 07:12 ghost

sudo rm -rf /usr/local/lib/node_modules brew install node

cozzbie avatar Dec 26 '16 20:12 cozzbie

@nodejs/ctc should we perhaps lock this thread and put suggested instructions at the top?

@cjihrig or @EvanCarroll did you have any luck with the installer?

MylesBorins avatar Dec 26 '16 20:12 MylesBorins

@TheAlphaNerd I'd be fine with a comment prepended (and separated) to the original message.

mscdex avatar Dec 26 '16 20:12 mscdex

Solved On my system Ubuntu: by following trick, I know this was created when I switched to previous version "4.1.1" from version "7.2.1" recently then NPM stopped working on switching back.

  1. Went again to version 4.1.1 by sudo n 4.1.1
  2. sudo npm update -g, it updated npm version it updated my npm package.
  3. sudo n 7.2.1, then npm started working Thanks,

himanshupathakpwd avatar Jan 04 '17 13:01 himanshupathakpwd

@himanshupathakpwd your solution works on mac as well. Scenario was the same. Thanks.

n 4.0.0 && npm update -g npm && n latest

msn0 avatar Jan 05 '17 11:01 msn0

I was able to solve this by following the instructions in this StackOverflow answer.

npm cache clean rm -Rf node_modules/ npm install

tobiaspatton-s4 avatar Jan 06 '17 22:01 tobiaspatton-s4

Just delete the problematic package from /usr/local/lib/node_modules, and reinstall it if you want. No need to delete the whole folder.

zhenwenc avatar Jan 11 '17 06:01 zhenwenc

I got this error when trying to uninstall a package from global scope. It worked for me to

n 6.4.0 && npm update -g && n latest && npm update -g

I actually had to do the update twice. I didn't use sudo.

More details about each step:

When I was on n latest (7.4.0) and tried npm update -g I got the same module not found error. It seems I had to go to just any older version and do npm update -g. Going to 6.4.0 and running it, I finally got:

(node:30490) fs: re-evaluating native module sources is not supported. If you are using the graceful-fs module, please update it to a more recent version.

followed by the update to npm. It installed npm 4.2.0.

When I did n latest after that, it put me back on 7.4.0, but npm -v was still 4.0.5. Weird. Actually that makes sense because it is only linking that version of npm to that version of node. So I ran npm update -g again while on 7.4.0, and now it installed npm 4.2.0 again. And npm -v finally returned 4.2.0

Now I could uninstall from global scope.

rhoboat avatar Jan 27 '17 18:01 rhoboat

npm install -g bower worked for me

grimace avatar Feb 05 '17 20:02 grimace