Skip to content

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

Closed

Description

@haleyparty
  • 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 ]

Activity

  1. added
    npmIssues and PRs related to the npm client dependency or the npm registry.
    on Jun 1, 2017
  2. zimbabao commented on Jun 1, 2017

    @zimbabao
    Contributor

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

  3. TimothyGu commented on Jun 1, 2017

    @TimothyGu
    Member

    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

    ?

  4. tomsoderlund commented on Jun 3, 2017

    @tomsoderlund

    @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
    
  5. suzannelock commented on Jun 4, 2017

    @suzannelock

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

  6. boyfunky commented on Jun 4, 2017

    @boyfunky

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

  7. lvl99 commented on Jun 7, 2017

    @lvl99

    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.

  8. Todmy commented on Jun 8, 2017

    @Todmy

    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

  9. lmj0011 commented on Jun 8, 2017

    @lmj0011

    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

  10. Todmy commented on Jun 9, 2017

    @Todmy

    @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

  11. ddffx commented on Jun 9, 2017

    @ddffx

    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.

  12. lmj0011 commented on Jun 9, 2017

    @lmj0011

    I as npm user should not care about removing node_modules

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

  13. ianoroceo commented on Jun 13, 2017

    @ianoroceo

    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

  14. RioBrewster commented on Jun 15, 2017

    @RioBrewster

    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

  15. 4 remaining items

  16. RioBrewster commented on Jun 16, 2017

    @RioBrewster
  17. gibfahn commented on Jun 17, 2017

    @gibfahn
    Member

    @RioBrewster what does which node print?

  18. RioBrewster commented on Jun 19, 2017

    @RioBrewster
  19. nesamouzehkesh commented on Jul 6, 2017

    @nesamouzehkesh

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

  20. TimothyGu commented on Jul 6, 2017

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

  21. added
    questionIssues asking questions about Node.js.
    and removed
    npmIssues and PRs related to the npm client dependency or the npm registry.
    on Jul 6, 2017
  22. robertjchristian commented on Jul 25, 2017

    @robertjchristian

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

    Try: rm -rf node_modules && npm install

  23. develucas commented on Aug 30, 2017

    @develucas

    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

  24. justijndepover commented on Sep 7, 2017

    @justijndepover

    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

  25. develucas commented on Sep 7, 2017

    @develucas

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

  26. justijndepover commented on Sep 7, 2017

    @justijndepover

    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.

  27. benmirkhah commented on Apr 23, 2018

    @benmirkhah

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionIssues asking questions about Node.js.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions