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

@Swelly did you install npm separately from node? Node v7 comes shipped with npm v3.10.8 and a fresh install of node with homebrew should be coming with that version.

what does which npm show?

MylesBorins avatar Nov 03 '16 20:11 MylesBorins

@TheAlphaNerd The reason that this happens is that the Node installer doesn't remove /usr/local/lib/node_modules/npm before installing the new version, so if somebody has a version of npm installed that's old enough that it doesn't include the fixed graceful-fs (somewhere / anywhere) in its own install tree, it's possible, in some cases, for the new install to end up using a stale old version of graceful-fs.

There's no easy way for npm to work around this itself without doing some super hacky stuff in a postinstall script, and the fix to the installer, as described above, should be pretty simple, so is there any way we can work to get it fixed there?

othiym23 avatar Nov 03 '16 20:11 othiym23

@othiym23 the user above said that they installed via homebrew not our installer.. which I just tested and it does in fact uninstall the npm directory before it installs.

I have an old branch where I tried to get an rm -rf /usr/local/lib/node_modules/npm working in the installer but could never get it to work https://github.com/thealphanerd/node/tree/rimraf-npm

edit: I lied the above branch was doing the rm -rf in the make file... I also had done some work on the installer but can't find it

MylesBorins avatar Nov 03 '16 20:11 MylesBorins

@othiym23 the user above said that they installed via homebrew not our installer.. which I just tested and it does in fact uninstall the npm directory before it installs.

It hasn't always, and in any case it puts each version of npm in its own Cellar/npm/<version> directory, so that's probably something else going on. The only versions of graceful-fs available to npm are all new enough to not rely on internals:

[email protected] /Users/ogd/Documents/projects/npm/npm
├── [email protected]
└─┬ [email protected]
  └─┬ [email protected]
    └─┬ [email protected]
      └─┬ [email protected]
        └── [email protected]

(That nyc dep is kinda dodgy, but it's a devDependency that won't get installed on a client machine.)

I can confirm with total certainty that this is a reproducible problem with the way the Node installer works, though. So at least that part is within our control to fix, and it should be. This regularly causes problems for npm users aside from this one, although I'm blanking at the moment on the last time we saw this.

othiym23 avatar Nov 03 '16 20:11 othiym23

@othiym23 so the main issue I ran into was trying to remove things in /usr/local/ with the installer... during the install phase it has admin privileges, but I could not figure out how to get it to remove

has to be fixed around https://github.com/nodejs/node/blob/master/tools/osx-pkg.pmdoc/02npm.xml#L8-L9

I can dig into this again tomorrow

MylesBorins avatar Nov 03 '16 20:11 MylesBorins

I'll dig in again too. I have some ideas on how we can do this.

evanlucas avatar Nov 03 '16 21:11 evanlucas

@TheAlphaNerd it's odd, I did a clean uninstall of Node through Homebrew and subsequently removed npm and all existing modules before attempting another Node install... yet I'be maintained an npm version of 3.3.8

Swelly avatar Nov 03 '16 21:11 Swelly

I experience this issue too. Clean install of CentOS 7, node v7.0.0 and npm v3.10.8 installed via the nodesource RPM repo. The issue occurs for me when I try to install the sqlite package.

stevenvergenz avatar Nov 03 '16 21:11 stevenvergenz

@Swelly @stevenvergenz Are you both sure that which npm produces the version of npm you just installed?

If those looks correct, can you try running npm ls --global graceful-fs? (And if that fails, due to the aforementioned issue, can you try running

find /usr/local/lib/node_modules -type d -name graceful-fs -print -exec grep version \{\}/package.json \;

...substituting for /usr/local/lib as necessary?)

Anything less than [email protected] is suspect, and we'll need to figure out how those deps got onto your system.

othiym23 avatar Nov 03 '16 21:11 othiym23

@othiym23

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

stevenvergenz avatar Nov 03 '16 21:11 stevenvergenz

Having an issue reinstalling Node / npm now with Homebrew.

When I run the regular $ brew install node npm doesn't get installed and ==>make install is hanging when I add the --without-npm flag to brew install node.

Swelly avatar Nov 03 '16 22:11 Swelly

@stevenvergenz What version of sqlite? I just ran npm install -S sqlite in a freshly-created test project with Node.js 7.0.0 and [email protected] and had no issues? I'm tempted to say your issue may be due to an obsolete version of node-pre-gyp or something else depended upon by sqlite.

othiym23 avatar Nov 03 '16 22:11 othiym23

@othiym23 It was sqlite 2.2, listed as a dependency for another project. The latest version of sqlite3 installed just fine and seems to work, so I'm not too worried about it anymore.

stevenvergenz avatar Nov 03 '16 23:11 stevenvergenz

So update on my end- I had to run $ brew upgrade homebrew/versions/ppl011 because my homebrew was way out of date. After that completed, I completely removed Node and npm $ rm -rf /usr/local/lib/node_modules $ rm -rf ~/.npm

And then installed Node again regularly with $ brew install node and now npm is at 3.10.8 and installing everything correctly.

Swelly avatar Nov 04 '16 00:11 Swelly

welll i did remove npm_modules in my app and reinsall all again and befor then i uninstalled nodejs and reinstall and problem gone.

emps avatar Nov 04 '16 12:11 emps

cd /usr/local/n/versions/node/7.0.0/ sudo bin/npm i -g npm4 cd /usr/local/bin/ sudo mv npm4 npm

then it resolved

shufanshijie avatar Nov 06 '16 10:11 shufanshijie

In my case, another library (Play Framework) was using an outdated version of graceful-fs (3.0.8). Having installed node & npm in my system, I just copied the directory /usr/local/lib/node_modules/npm/node_modules/graceful-fs/ to .../project/target/node-modules/webjars/npm/node_modules/graceful-fs/

juanmirocks avatar Nov 07 '16 11:11 juanmirocks

I had this problem in my existing repos after a fresh install of OSX, homebrew and node.

Within each repo I just ran rm -R node_modules followed by npm install and it seemed to fix everything.

Hopefully helps someone else.

humanjpg avatar Nov 07 '16 18:11 humanjpg

The issue for me was actually with nodemon. I realized I was only seeing this error when using nodemon. I reinstalled nodemon npm install -g nodemon and it seems to be working now. Note that I also used the steps provided by @spelunk.

kjprice avatar Nov 10 '16 15:11 kjprice

Can also be caused by gulp.js since gulp v3 is still using a decpricated version of graceful-fs. The fix is to downgrade node version to v6.

Edit:

Ok, I should've said it is a workaround and not a fix. I'm just putting it here to help people using gulp (like me) who ends up in this thread to proceed with their respective business.

adonespitogo avatar Nov 12 '16 10:11 adonespitogo