Node: Cannot find module 'internal/fs' when npm install on Node 8 using mac

Created on 1 Jun 2017  Â·  28Comments  Â·  Source: nodejs/node

  • Version: v8.0.0
  • Platform: Darwin Haleys-MacBook-Air.local 15.6.0 Darwin Kernel Version 15.6.0: Tue Apr 11 16:00:51 PDT 2017; root:xnu-3248.60.11.5.3~1/RELEASE_X86_64 x86_64
  • Subsystem:

Was getting this error consistently when trying to install packages using Node v8.0.0. Using nvm with v6.10.3 solved the issue. Stack trace:

```0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'install' ]
2 info using [email protected]
3 info using [email protected]
4 verbose stack Error: Cannot find module 'internal/fs'
4 verbose stack at Function.Module._resolveFilename (module.js:485:15)
4 verbose stack at Function.Module._load (module.js:437:25)
4 verbose stack at Module.require (module.js:513:17)
4 verbose stack at require (internal/module.js:11:18)
4 verbose stack at evalmachine.:40:20
4 verbose stack at Object. (/usr/local/lib/node_modules/npm/node_modules/cmd-shim/node_modules/graceful-fs/fs.js:11:1)
4 verbose stack at Module._compile (module.js:569:30)
4 verbose stack at Object.Module._extensions..js (module.js:580:10)
4 verbose stack at Module.load (module.js:503:32)
4 verbose stack at tryModuleLoad (module.js:466:12)
4 verbose stack at Function.Module._load (module.js:458:3)
4 verbose stack at Module.require (module.js:513:17)
4 verbose stack at require (internal/module.js:11:18)
4 verbose stack at Object. (/usr/local/lib/node_modules/npm/node_modules/cmd-shim/node_modules/graceful-fs/graceful-fs.js:3:27)
4 verbose stack at Module._compile (module.js:569:30)
4 verbose stack at Object.Module._extensions..js (module.js:580:10)
5 verbose cwd /Users/halebash/newedenfaces
6 verbose Darwin 15.6.0
7 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "install"
8 verbose node v8.0.0
9 verbose npm v5.0.0
10 error code MODULE_NOT_FOUND
11 error Cannot find module 'internal/fs'
12 verbose exit [ 1, true ]

question

Most helpful comment

@haleyparty I had the same problem, but solved it by reinstalling node using brew.

That gave me a problem with npm, which I fixed with these instructions:

sudo chmod -R 777 /usr/local/lib
brew postinstall node

All 28 comments

npm 5 has some issues, does it work with npm 4.2 or any 4.x version?.

This looks like a bad case of dependency management, as it seems like the code that's erroring out comes from graceful-fs v3, which is known to not work with recent Node.js versions. On the other hand, the latest version of npm (5.0.0, the one bundled with Node.js 8.0.0) does not depend on graceful-fs v3 in any way.

Looking at the path of the problematic file /usr/local/lib/node_modules/npm/node_modules/cmd-shim/node_modules/graceful-fs/fs.js, my guess would be that you have set npm prefix (npm config get prefix) to a global directory that is shared between different Node.js versions (like /usr/local). This is bad: global Node.js modules should always be segregated by version, to avoid dependency troubles like this, and to ensure native modules are rebuilt correctly. In fact, a recent enough nvm _should_ warn about problematic npm config get prefix settings.

Can you show the output of

  1. npm config get prefix
  2. nvm --version

?

@haleyparty I had the same problem, but solved it by reinstalling node using brew.

That gave me a problem with npm, which I fixed with these instructions:

sudo chmod -R 777 /usr/local/lib
brew postinstall node

anyone able to solve this? i am having the same issue with node v5 and npm v4

anyone able to solve this? having same issue with node v5 and npm v4

I'm having issues and I'm using nvm to manage my node install. Seems that whenever I install whatever version (6, 7, 8) I still get the same issue.

I have same problem, but with other packages(boom, request, tough-cookie etc.) and each time with random package. But it always throws error at Function.Module._resolveFilename (module.js:485:15).
I use:
node - v8.0.0
npm - v5.0.3
n - v2.1.7

Assuming your node_modules dir already existed when you tried npm install, deleting the node_modules dir and installing everything from scratch gets rid of odd errors like these

rm -fr node_modules/

then

npm install

there were probably some binaries that needed recompiling with node v8

@lmj0011 yes, look like it fixes my problem. Thank you.

Anyway I think it is not a better solution. I as npm user should not care about removing node_modules. Better is as it was done in previous versions of npm

FWIW I encountered the same problem this morning on my Mac (Sierra, 10.12.4). Then installed nvm and used it to install the latest version node 8.1.0, npm 5.0.3. It worked.

I as npm user should not care about removing node_modules

When you choose to upgrade node versions, I believe you should

same problem that I have.
I already completely removed node on my mac and installed it back using homebrew

Error: Cannot find module 'natives'
at Function.Module._resolveFilename (module.js:485:15)
at Function.Module._load (module.js:437:25)
at Module.require (module.js:513:17)
at require (internal/module.js:11:18)
at Object. (/Users/usr/IdeaProjects/test/node_modules/vinyl-fs/node_modules/graceful-fs/fs.js:1:80)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)

macOS Sierra version 10.12.3
node - v8.1.0
npm - v5.0.3

I am having the same issue. I completely uninstalled node and npm and reinstalled them using homebrew.

I also tried the suggestion above - removing node_modules and re-running npm install

That gave me a bunch of "SKIPPING OPTIONAL DEPENDENCY" messages, and finally dying with:

npm ERR! path /Users/myname/Sites/mysite/node_modules/.staging/gulp-scss-lint-f7619bde/node_modules/bluebird
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall rename
npm ERR! enoent ENOENT: no such file or directory, rename '/Users/myname/Sites/mysite/node_modules/.staging/gulp-scss-lint-f7619bde/node_modules/bluebird' -> '/Users/myname/Sites/mysite/node_modules/.staging/bluebird-4efd5b8a'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent 

Just for grins I wanted to see what happened when trying to run npm.

When I try running again I get the same error.

"Error: Cannot find module 'internal/fs'"
blah blah blah

Also running:

MacOS Sierra 10.12.5
node v8.1.2
npm v5.0.3

i reverted back to node v6.11.0 and npm v3.10.10 to make this work for me

node 7,node 8 has this problem same as @ianoroceo
node 6 works well

Thanks everyone for your help.
I was able to downgrade node - but no matter what I try npm in stuck at 5.
I tried uninstalling npm using: npm uninstall npm@5 and npm uninstall npm
It runs but npm -v still sits at v5.0.3. I try uninstalling using:
brew uninstall npm
I get Error: Permission denied - /usr/local/include/node
(I don't have admin privileges).
What next?

@RioBrewster I find these steps helpful - https://gist.github.com/TonyMtz/d75101d9bdf764c890ef
it's the same steps I followed to uninstall node and npm on my mac

and after uninstalling, I just download the node js installer at the site - https://nodejs.org/en/

Thanks – but I don’t have admin so I can’t do sudo.

From: ianoroceo notifications@github.com
Reply-To: nodejs/node reply@reply.github.com
Date: Friday, June 16, 2017 at 10:47 AM
To: nodejs/node node@noreply.github.com
Cc: Julie Lewis Julie.Lewis@cpa.texas.gov, Mention mention@noreply.github.com
Subject: Re: [nodejs/node] Cannot find module 'internal/fs' when npm install on Node 8 using mac (#13361)

CAUTION: This email originated from outside of the Texas Comptroller's email system.
DO NOT click links or open attachments unless you expect them from the sender and know the content is safe.

@RioBrewsterhttps://github.com/riobrewster I find these steps helpful - https://gist.github.com/TonyMtz/d75101d9bdf764c890ef
it's the same steps I followed to uninstall node and npm on my mac

and after uninstalling, I just download the node js installer at the site - https://nodejs.org/en/

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHubhttps://github.com/nodejs/node/issues/13361#issuecomment-309061432, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AB3EJYDGSMf_JaoF-tZ7BWoINr-iKdwVks5sEqN1gaJpZM4Nshv2.

@riobrewster what does which node print?

/usr/local/opt/node@6/bin/node

From: Gibson Fahnestock notifications@github.com
Reply-To: nodejs/node reply@reply.github.com
Date: Saturday, June 17, 2017 at 6:31 PM
To: nodejs/node node@noreply.github.com
Cc: Julie Lewis Julie.Lewis@cpa.texas.gov, Mention mention@noreply.github.com
Subject: Re: [nodejs/node] Cannot find module 'internal/fs' when npm install on Node 8 using mac (#13361)

CAUTION: This email originated from outside of the Texas Comptroller's email system.
DO NOT click links or open attachments unless you expect them from the sender and know the content is safe.

@RioBrewsterhttps://github.com/riobrewster what does which node print?

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHubhttps://github.com/nodejs/node/issues/13361#issuecomment-309246582, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AB3EJYdI0jCLYyJke8u1etSpG9AVCz3Aks5sFGG_gaJpZM4Nshv2.

switching to v6.11.0 solved the problem for me. Thanks @ianoroceo

As I've pointed out in https://github.com/nodejs/node/issues/13361#issuecomment-305435643, it is necessary to separate global packages installed for a specific Node.js version. Many of the issues described here are caused by assuming (intentionally or unintentionally) packages (like npm and its dependencies) installed for an older version of Node.js will work for a newer Node.js. In other words, this is not a bug in Node.js, but rather in your setup.

To fix this, delete node_modules and start over is generally the best solution. And after doing so, I recommend using a Node.js version manager that manages npm and global packages for you. nvm does this very well. On the other hand, Homebrew and most other system-wide package installers usually do not do this well.

This thread has grown very long, and unrelated issues are starting to creep in. I will close this issue now, though we will be just as happy to help you figure this out at nodejs/help or IRC.

Could be conflicts in node_modules folder. Good idea to make sure it's clean.

Try: rm -rf node_modules && npm install

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

isn't whereis to locate a program? if I run whereis node_modules in my terminal I get no response.
Anyway, I looked up both folders and i don't have a folder /usr/lib/node_modules.

So should I still delete the latter?

Running Node v7.9.0

@justijndepover whereis also searches for sources, so I think directories are also a part of sources. Please be aware that how you've installed your nodejs is important rather than existence of particular directories. Basing on your comment only is hard to imagine what your problem really is. As I see here, the genesis of this broken behavior might be different for different cases. What is your case ?

I had node installed via the MacOS installer. I followed this guide to uninstall Node. Then I reinstalled everything with Homebrew. Now everything works again.

Reverting to node v6.9.5 fixed it for me too.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

willnwhite picture willnwhite  Â·  3Comments

dfahlander picture dfahlander  Â·  3Comments

fanjunzhi picture fanjunzhi  Â·  3Comments

ksushilmaurya picture ksushilmaurya  Â·  3Comments

Icemic picture Icemic  Â·  3Comments