On OSX 10.7+ and xcode 10+ I'm not able to install some project dependencies using npm.
NODE and NODE-GYP versions:
dom:~workspace/my_project$ nvm use 0.10.36
Now using node v0.10.36 (npm v2.15.1)
dom:~workspace/my_project$ node-gyp -v
v3.3.1
Running the npm install
command, it throws an error compiling the C++ dependecy:
dom:~workspace/my_project$ npm i node-expat
-
> node-expat@2.3.17 install /Users/dom/workspace/my_project/node_modules/node-expat
> node-gyp rebuild
CC(target) Release/obj.target/expat/deps/libexpat/lib/xmlparse.o
CC(target) Release/obj.target/expat/deps/libexpat/lib/xmltok.o
CC(target) Release/obj.target/expat/deps/libexpat/lib/xmlrole.o
LIBTOOL-STATIC Release/libexpat.a
CXX(target) Release/obj.target/node_expat/node-expat.o
warning: include path for stdlibc++ headers not found; pass '-stdlib=libc++' on the command line to use the libc++ standard library instead [-Wstdlibcxx-not-found]
In file included from ../node-expat.cc:1:
In file included from ../../nan/nan.h:54:
In file included from /Users/dom/.node-gyp/6.11.4/include/node/node.h:42:
/Users/dom/.node-gyp/6.11.4/include/node/v8.h:21:10: fatal error: 'utility' file not found
#include <utility>
^~~~~~~~~
1 warning and 1 error generated.
make: *** [Release/obj.target/node_expat/node-expat.o] Error 1
...
Apple has deprecated the stdlibc++
lib in favor of libc++
and the old\not updated NPM packages that have C++ dependencies to compile throw an error similar to the above one.
Edit the file /Users/dom/.node-gyp/0.10.36/common.gypi changing the MACOSX_DEPLOYMENT_TARGET from 10.5 to 10.7 (or higher) because the libc++
requires OSX 10.7+.
Also add 'CLANG_CXX_LIBRARY': 'libc++',
on row below, in order to tell to OSX to use the newer lib on all packeges compiling.
How it will appear:
...
'PREBINDING': 'NO', # No -Wl,-prebind
'MACOSX_DEPLOYMENT_TARGET': '10.7', # -mmacosx-version-min=10.7
'CLANG_CXX_LIBRARY': 'libc++',
# 'CLANG_CXX_LANGUAGE_STANDARD':'c++11', # OPTIONAL. this may be not necessary
# 'GCC_VERSION': 'com.apple.compilers.llvm.clang.1_0' # OPTIONAL. this may be not necessary
'USE_HEADERMAP': 'NO',
...
Apply the same change for all installed node verions (I use NVM in order to use multiple node instances on same machine).
E.g. for NODE 4.4.7:
dom:~workspace/my_project$ nvm use 4.4.7
Now using node v4.4.7 (npm v2.15.8)
dom:~workspace/my_project$ node-gyp -v
v3.8.0
Edit the file /Users/dom/.node-gyp/4.4.7/include/node/common.gypi changing the MACOSX_DEPLOYMENT_TARGET from 10.5 to 10.7.
Also add 'CLANG_CXX_LIBRARY': 'libc++',
on row below.
dom:~workspace/my_project$ npm i node-expat
-
> node-expat@2.3.17 install /Users/dom/workspace/my_project/node_modules/node-expat
> node-gyp rebuild
CC(target) Release/obj.target/expat/deps/libexpat/lib/xmlparse.o
CC(target) Release/obj.target/expat/deps/libexpat/lib/xmltok.o
CC(target) Release/obj.target/expat/deps/libexpat/lib/xmlrole.o
LIBTOOL-STATIC Release/libexpat.a
CXX(target) Release/obj.target/node_expat/node-expat.o
SOLINK_MODULE(target) Release/node_expat.node
node-expat@2.3.17 node_modules/node-expat
Enjoy it! :D