Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
shufanshijie opened this issue Oct 31, 2016 · 95 comments
Closed

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

shufanshijie opened this issue Oct 31, 2016 · 95 comments
Labels
install Issues and PRs related to the installers. npm Issues and PRs related to the npm client dependency or the npm registry.

Comments

@shufanshijie
Copy link

shufanshijie commented Oct 31, 2016

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'
@cjihrig
Copy link
Contributor

cjihrig commented Oct 31, 2016

Hm, can you read over the discussion in #9355.

@Fishrock123
Copy link
Contributor

I'm getting a #3606 vibe from these. Smells like an installer problem.

@Fishrock123
Copy link
Contributor

Fishrock123 commented Oct 31, 2016

@shufanshijie

What is the output of node -v and npm -v?
How did you install Node.js?

@Fishrock123
Copy link
Contributor

Fishrock123 commented Oct 31, 2016

If you run rm -rf /usr/local/lib/node_modules/npm and then re-install Node.js does it work?

@addaleax addaleax added the npm Issues and PRs related to the npm client dependency or the npm registry. label Oct 31, 2016
@thefourtheye
Copy link
Contributor

Unable to reproduce the problem.

➜  ~ node -v
v7.0.0
➜  ~ npm -v
3.10.8
➜  ~ uname -v
Darwin Kernel Version 15.6.0: Thu Sep  1 15:01:16 PDT 2016; root:xnu-3248.60.11~2/RELEASE_X86_64
➜  ~ npm i iconv-lite
/Users/thefourtheye
└── [email protected]

Could be because of the stale npm installation, but not sure how that could have happened though. Please try what @Fishrock123 suggested above.

@giulio-sefaira
Copy link

giulio-sefaira commented Nov 1, 2016

Same problem for me on a MacOsX Sierra:

$ uname -v
Darwin Kernel Version 16.1.0: Thu Oct 13 21:26:57 PDT 2016; root:xnu-3789.21.3~60/RELEASE_X86_64
$ node -v
v7.0.0
$ npm -v
3.10.8

I tried to uninstall / reinstall, but it didn't fix the problem

@gibfahn
Copy link
Member

gibfahn commented Nov 1, 2016

@shufanshijie @giulio-sefaira How did you install node? With brew or nvm? Or directly from https://nodejs.org/en/download/ ?

@giulio-sefaira
Copy link

hi @gibfahn . I used brew. I uninstalled node, wiped entirely the node_modules library (rm -rf /usr/local/lib/node_modules) and reinstalled by brew

@OnceMore2020
Copy link

I tried to reinstall node with brew and delete entire /usr/local/lib/node_modules, the error still happens.

@Fishrock123
Copy link
Contributor

@giulio-sefaira @OnceMore2020 could you please run which npm?

@giulio-sefaira
Copy link

giulio-sefaira commented Nov 1, 2016

@Fishrock123

$ which npm
npm is /usr/local/bin/npm
npm is /usr/local/bin/npm
npm is /usr/local/bin/npm

@giulio-sefaira
Copy link

giulio-sefaira commented Nov 1, 2016

$ /usr/local/bin/npm -v 3.10.8

@Leolik
Copy link

Leolik commented Nov 1, 2016

get this error in Ubuntu 16.04
node -v = v7.0.0
npm -v = 3.10.8

@gibfahn
Copy link
Member

gibfahn commented Nov 1, 2016

@Leolik How did you install node?

@Leolik
Copy link

Leolik commented Nov 1, 2016

@gibfahn sudo n latest
but after reading #9355 and removing /usr/local/lib/node_modules/ - error not reproduced

@vodrazka
Copy link

vodrazka commented Nov 2, 2016

Also after removing /usr/local/lib/node_modules/ and the local project node_modules - error gone.

@gabrielperales
Copy link

I solved this issue thanks to the answer of @Leolik and @fane89

@spelunk
Copy link

spelunk commented Nov 2, 2016

I ran into this problem too, but was able to resolve it by rolling back to an older version of node/npm and forcing a "flush" of the npm module:

$ sudo n 6.
$ sudo npm install -g [email protected]
$ sudo npm install -g npm@next
$ sudo n 7.

@Fishrock123 Fishrock123 added the install Issues and PRs related to the installers. label Nov 3, 2016
@Swelly
Copy link

Swelly commented Nov 3, 2016

Using Mac OS Sierra and installed Node + npm via Homebrew.

This is still not functional for me. I've gone through the thread and continue to have:

Cannot find module 'internal/fs'

verbose cli 'install' ]
2 info using [email protected]
3 info using [email protected]
4 verbose stack Error: Cannot find module 'internal/fs'

I've removed /usr/local/lib/node_modules/ and reinstalled node etc etc. to no avial @giulio-sefaira are you in the clear yet?

@addaleax
Copy link
Member

addaleax commented Nov 3, 2016

Since I assume this kind of thing is also popping up on the npm issue tracker… @nodejs/npm @kenany do you know what’s up with this?

@MylesBorins
Copy link
Contributor

@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?

@othiym23
Copy link
Contributor

othiym23 commented Nov 3, 2016

@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?

@MylesBorins
Copy link
Contributor

MylesBorins commented Nov 3, 2016

@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

@othiym23
Copy link
Contributor

othiym23 commented Nov 3, 2016

@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.

@MylesBorins
Copy link
Contributor

@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

@evanlucas
Copy link
Contributor

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

@pmc-a
Copy link

pmc-a commented May 29, 2017

Seen this issue with v7.10.0, solution was downgrading to v6.10.3 like @balinterdi mentioned. Also needed to remove node_modules and reinstall.

@adamreisnz
Copy link

adamreisnz commented May 31, 2017

Ran into this issue when using lerna bootstrap. Nothing suggested here was feasible or worked, so in the end the simple solution was to use yarn instead via lerna bootstrap --npm-client=yarn

This was with Node 8 and npm 5 btw.

@haleyparty
Copy link

Also ran into this issue when on Node 8. Set my nvm to v6.10.3 fixed the issue.

@TimothyGu
Copy link
Member

@adamreisnz @haleyparty Could (one of) you create a new issue with full stack trace? Thanks!

@haleyparty
Copy link

@TimothyGu Will do now!

@TimothyGu
Copy link
Member

For posterity: #13361

@panpepson
Copy link

Hi,

ive removed all the node.js package on my OS

apt-get purge node.js

and manually remove/clear

/home/user*/(.npm,.ionic), /root/(.npm,.ionic), /usr/lib/node_modules

manual removal of the remainder helped and update your OS and new install node.js and ionic

cu

1 similar comment
@panpepson
Copy link

Hi,

ive removed all the node.js package on my OS

apt-get purge node.js

and manually remove/clear

/home/user*/(.npm,.ionic), /root/(.npm,.ionic), /usr/lib/node_modules

manual removal of the remainder helped and update your OS and new install node.js and ionic

cu

@dtruffaut
Copy link

On Windows, I confirm that deleting the directory :

C:\Users<your_username>\AppData\Roaming\npm\node_modules

solves the issue.

@jspblm
Copy link

jspblm commented Jul 9, 2017

@Fishrock123 Solution works for me on node v8.1.3 and npm 5.0.3

@MichalZalecki
Copy link

@Fishrock123 solution is generally working 💥

If it's not working for you make sure that your version of npm is actually under /usr/local/lib/node_modules/npm. Run which npm. For node installed e.g. through ansible nodejs role it can be in: ~/nodejs/bin/npm. If that's the case then you want to rm -rf ~/nodejs/lib/node_modules/npm. Reinstall and you should be fine.

@redexp
Copy link

redexp commented Jul 22, 2017

I get this error when I switched to older node with nvm.

Here my solution. I tried in console which bower it gives me /usr/bin/bower it was symlink to /usr/lib/node_modules/bower/bin/bower so I just removed symlink sudo rm /usr/bin/bower and removed module itself rm -rf /usr/lib/node_modules/bower and installed bower again npm i -g bower. After that was no error

@shahzadns
Copy link

For me this error came after using gulp serve command on angular1-gulp project, by removing the local node_modules folder and doing npm install solved this error.

node 7.9.0
npm 4.2.0
node installed using nvm version 0.25.1
Mac OS Sierra.

Hope this will help someone.
Cheers !

@develucas
Copy link

I also experienced it lately and solved it in the following way. For me there was a conflict but at the system level and it was caused by not cleaned properly, old nodejs installation. I couldn't use latest bower package, so after reading your comments

>whereis node_modules
node_modules: /usr/lib/node_modules /usr/local/lib/node_modules

I've deleted the second directory as it was for nodejs 6.x, and all returned to normal.

Cheers

@ghost
Copy link

ghost commented Sep 7, 2017

I had a similar problem and it seems that reinstalling gulp and also deleting node_modules directory in my project folder fixed the problem. I use node version 8.0.0 and npm 5.0.0.

EDIT ~ I mean this is for people having problem with graceful-fs module working with gulp.

@taylorc93
Copy link

I ran into this issue as well when using lerna bootstrap. Turned out I had a node_modules folder in my home directory that had a copy of NPM in it that lerna was using. No idea how that got there, but removing it did the trick.

@zhuziyi1989
Copy link

zhuziyi1989 commented Mar 28, 2018

Reference solution: #9355

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
install Issues and PRs related to the installers. npm Issues and PRs related to the npm client dependency or the npm registry.
Projects
None yet
Development

No branches or pull requests