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

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

Closed
haleyparty opened this issue Jun 1, 2017 · 28 comments
Closed
Labels
question Issues that look for answers.

Comments

@haleyparty
Copy link

  • 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:

1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'install' ]
2 info using npm@5.0.0
3 info using node@v8.0.0
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.<anonymous>:40:20
4 verbose stack     at Object.<anonymous> (/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.<anonymous> (/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 ]
@mscdex mscdex added npm Issues and PRs related to the npm client dependency or the npm registry. v8.x labels Jun 1, 2017
@zimbabao
Copy link
Contributor

zimbabao commented Jun 1, 2017

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

@TimothyGu
Copy link
Member

TimothyGu commented Jun 1, 2017

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

?

@tomsoderlund
Copy link

tomsoderlund commented Jun 3, 2017

@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

@suzannelock
Copy link

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

@boyfunky
Copy link

boyfunky commented Jun 4, 2017

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

@lvl99
Copy link

lvl99 commented Jun 7, 2017

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.

@Todmy
Copy link

Todmy commented Jun 8, 2017

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

@lmj0011
Copy link

lmj0011 commented Jun 8, 2017

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

@Todmy
Copy link

Todmy commented Jun 9, 2017

@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

@ddffx
Copy link

ddffx commented Jun 9, 2017

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.

@lmj0011
Copy link

lmj0011 commented Jun 9, 2017

I as npm user should not care about removing node_modules

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

@ianoroceo
Copy link

ianoroceo commented Jun 13, 2017

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

@RioBrewster
Copy link

RioBrewster commented Jun 15, 2017

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

@ianoroceo
Copy link

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

@rawbin-
Copy link

rawbin- commented Jun 16, 2017

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

@RioBrewster
Copy link

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?

@ianoroceo
Copy link

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

@RioBrewster
Copy link

RioBrewster commented Jun 16, 2017 via email

@gibfahn
Copy link
Member

gibfahn commented Jun 17, 2017

@RioBrewster what does which node print?

@RioBrewster
Copy link

RioBrewster commented Jun 19, 2017 via email

@nesamouzehkesh
Copy link

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

@TimothyGu
Copy link
Member

As I've pointed out in #13361 (comment), 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.

@TimothyGu TimothyGu added question Issues that look for answers. and removed npm Issues and PRs related to the npm client dependency or the npm registry. v8.x labels Jul 6, 2017
@robertjchristian
Copy link

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

Try: rm -rf node_modules && npm install

@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

@justijndepover
Copy link

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

@develucas
Copy link

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

@justijndepover
Copy link

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.

@benmirkhah
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Issues that look for answers.
Projects
None yet
Development

No branches or pull requests