13

When running yarn install for a Node 6.11.1 project on macOS (Mojave) the node-gyp rebuild for hiredis fails:

XCode commandline tools have been installed via sudo xcode-select --install.

Node is installed via nvm.

error /Users/alexzeitler/src/some-project/node_modules/hiredis: Command failed.
Exit code: 1
Command: node-gyp rebuild
Arguments:
Directory: /Users/alexzeitler/src/some-project/node_modules/hiredis
Output:
gyp info it worked if it ends with ok
gyp info using node-gyp@3.4.0
gyp info using node@6.11.1 | darwin | x64
gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
gyp info spawn /usr/bin/python
gyp info spawn args [ '/Users/alexzeitler/.nvm/versions/node/v6.11.1/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'make',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/alexzeitler/src/some-project/node_modules/hiredis/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/alexzeitler/.nvm/versions/node/v6.11.1/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/alexzeitler/.node-gyp/6.11.1/include/node/common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=/Users/alexzeitler/.node-gyp/6.11.1',
gyp info spawn args   '-Dnode_gyp_dir=/Users/alexzeitler/.nvm/versions/node/v6.11.1/lib/node_modules/npm/node_modules/node-gyp',
gyp info spawn args   '-Dnode_lib_file=node.lib',
gyp info spawn args   '-Dmodule_root_dir=/Users/alexzeitler/src/some-project/node_modules/hiredis',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'build',
gyp info spawn args   '-Goutput_dir=.' ]
gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
  CC(target) Release/obj.target/hiredis-c/deps/hiredis/sds.o
  CC(target) Release/obj.target/hiredis-c/deps/hiredis/read.o
  LIBTOOL-STATIC Release/hiredis-c.a
  CXX(target) Release/obj.target/hiredis/src/hiredis.o
warning: include path for stdlibc++ headers not found; pass '-std=libc++' on the command line to use the libc++ standard library instead [-Wstdlibcxx-not-found]
In file included from ../src/hiredis.cc:1:
In file included from ../src/reader.h:1:
In file included from ../../nan/nan.h:51:
In file included from /Users/alexzeitler/.node-gyp/6.11.1/include/node/node.h:42:
/Users/alexzeitler/.node-gyp/6.11.1/include/node/v8.h:21:10: fatal error: 'utility' file not found
#include <utility>
         ^~~~~~~~~
1 warning and 1 error generated.
make: *** [Release/obj.target/hiredis/src/hiredis.o] Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/Users/alexzeitler/.nvm/versions/node/v6.11.1/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:276:23)
gyp ERR! stack     at emitTwo (events.js:106:13)
gyp ERR! stack     at ChildProcess.emit (events.js:191:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12)
gyp ERR! System Darwin 18.0.0
gyp ERR! command "/Users/alexzeitler/.nvm/versions/node/v6.11.1/bin/node" "/Users/alexzeitler/.nvm/versions/node/v6.11.1/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/alexzeitler/src/some-project/node_modules/hiredis
gyp ERR! node -v v6.11.1
gyp ERR! node-gyp -v v3.4.0
gyp ERR! not ok

Update: using Node 8.11.1 via nvm everything works fine (but moving to 8.11.1 is not an option in this particular project yet).

Alexander Zeitler
  • 11,919
  • 11
  • 81
  • 124

4 Answers4

28

This fixed it for me:

CXXFLAGS="-mmacosx-version-min=10.9" LDFLAGS="-mmacosx-version-min=10.9" yarn

Tried the answer from here.

Alexander Zeitler
  • 11,919
  • 11
  • 81
  • 124
15

If you are using XCode 10, you will notice that if you navigate to the /usr, you will not see a folder called include anymore, which is why the terminal complains of the absence of the header files which is contained inside the 'include' folder.

  1. Go here then download and install: Command Line Tools (macOS 10.14) for Xcode 10
  2. open ~/../../Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
  3. run CXXFLAGS="-mmacosx-version-min=10.9" LDFLAGS="-mmacosx-version-min=10.9" yarn install

Then you should be good to go.

Michal
  • 4,952
  • 8
  • 30
  • 63
  • Thanks, after installing the package, the `include` folder exists but the `node-gyp` error also remains. – Alexander Zeitler Oct 03 '18 at 19:10
  • @AlexanderZeitler Are you compiling your own node C++ addon? Or is this happening after `npm install`? – Michal Oct 03 '18 at 21:25
  • It’s happening during npm install. – Alexander Zeitler Oct 03 '18 at 23:31
  • If I ignore the error, I can't install my npm packages. How do you deal with that? – Alexander Zeitler Oct 04 '18 at 11:54
  • @AlexanderZeitler The error happens after installing node modules. You should have node modules installed. Please also try `rm -rf node_modules && yarn cache clean --force && yarn install` and tell me if this helps. Maybe you need to remove existing node modules, clear yarn cache and install node modules. Also, do you have XCode 10 installed? – Michal Oct 04 '18 at 18:45
  • Tried it but didn't fix it. XCode 10 is installed. – Alexander Zeitler Oct 04 '18 at 19:25
  • Is the error really the same error as before? `node-gyp` and `npm` together print so much information when something fails that it's sometimes jolly hard to find the real reason for the failure. Please double-check that the error you are seeing is still `fatal error: 'utility' file not found`. – Robert Rossmann Oct 05 '18 at 07:50
  • @Michal Would you mind validating my answer fixes it for you as well? https://stackoverflow.com/a/52674032/90800 – Alexander Zeitler Oct 05 '18 at 22:34
  • 1
    @AlexanderZeitler Looks awesome. :) – Michal Oct 08 '18 at 18:46
  • 1
    Its working for bower install too . CXXFLAGS="-mmacosx-version-min=10.9" LDFLAGS="-mmacosx-version-min=10.9" bower install – Afshin Teymoori Dec 03 '18 at 00:03
0

Faced this same issue once on Linux platform. Removing node_modules and .node-gyp/ directory from home fixed the error.

Dhirendra
  • 780
  • 9
  • 26
0

I stuck in this error for a long time and I paid the price... I ruined a laptop!

at the end this is the solution that worked for me:

the problem is not with node-gyp or hiredis.

there are 2 possibilities:

1- you're using incompatible node version

2- python symbolic link doesn't exist(my problem was this one)

the problem is with new version of python will remove a symbolic link and we should re-create the link:

install newest version of python:

brew install python

and after that create the symbolic link:


ln -s -f /usr/local/bin/python3.9 /usr/local/bin/python

of-course instead of 3.9 you should put your python version.

Raskul
  • 1,674
  • 10
  • 26