Search code examples
node.jsmacosnpmlibcurlnode-libcurl

node-libcurl installation fails on MacOS Catalina: clang: error: no such file or directory: '/usr/include'


I simply wanted to install insomnia-inso on a Mac (Catalina) which has a dependency to node-libcurl and got the following error:

npm install -g node-libcurl

> node-libcurl@2.2.0 install /Users/jonashecht/dev/spring-boot/spring-boot-openapi-kong/node_modules/node-libcurl
> node-pre-gyp install --fallback-to-build

node-pre-gyp WARN Using request for node-pre-gyp https download
  CXX(target) Release/obj.target/node_libcurl/src/node_libcurl.o
clang: error: no such file or directory: '/usr/include'
make: *** [Release/obj.target/node_libcurl/src/node_libcurl.o] Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23)
gyp ERR! stack     at ChildProcess.emit (node:events:327:20)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:277:12)
gyp ERR! System Darwin 19.6.0
gyp ERR! command "/usr/local/Cellar/node/15.1.0/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "build" "--fallback-to-build" "--module=/Users/jonashecht/dev/spring-boot/spring-boot-openapi-kong/node_modules/node-libcurl/lib/binding/node_libcurl.node" "--module_name=node_libcurl" "--module_path=/Users/jonashecht/dev/spring-boot/spring-boot-openapi-kong/node_modules/node-libcurl/lib/binding" "--napi_version=7" "--node_abi_napi=napi" "--napi_build_version=0" "--node_napi_label=node-v88"
gyp ERR! cwd /Users/jonashecht/dev/spring-boot/spring-boot-openapi-kong/node_modules/node-libcurl
gyp ERR! node -v v15.1.0
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok
node-pre-gyp ERR! build error
node-pre-gyp ERR! stack Error: Failed to execute '/usr/local/Cellar/node/15.1.0/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js build --fallback-to-build --module=/Users/jonashecht/dev/spring-boot/spring-boot-openapi-kong/node_modules/node-libcurl/lib/binding/node_libcurl.node --module_name=node_libcurl --module_path=/Users/jonashecht/dev/spring-boot/spring-boot-openapi-kong/node_modules/node-libcurl/lib/binding --napi_version=7 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v88' (1)
node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (/Users/jonashecht/dev/spring-boot/spring-boot-openapi-kong/node_modules/node-pre-gyp/lib/util/compile.js:83:29)
node-pre-gyp ERR! stack     at ChildProcess.emit (node:events:327:20)
node-pre-gyp ERR! stack     at maybeClose (node:internal/child_process:1055:16)
node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:288:5)
node-pre-gyp ERR! System Darwin 19.6.0
node-pre-gyp ERR! command "/usr/local/Cellar/node/15.1.0/bin/node" "/Users/jonashecht/dev/spring-boot/spring-boot-openapi-kong/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd /Users/jonashecht/dev/spring-boot/spring-boot-openapi-kong/node_modules/node-libcurl
node-pre-gyp ERR! node -v v15.1.0
node-pre-gyp ERR! node-pre-gyp -v v0.15.0
node-pre-gyp ERR! not ok
Failed to execute '/usr/local/Cellar/node/15.1.0/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js build --fallback-to-build --module=/Users/jonashecht/dev/spring-boot/spring-boot-openapi-kong/node_modules/node-libcurl/lib/binding/node_libcurl.node --module_name=node_libcurl --module_path=/Users/jonashecht/dev/spring-boot/spring-boot-openapi-kong/node_modules/node-libcurl/lib/binding --napi_version=7 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v88' (1)

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node-libcurl@2.2.0 install: `node-pre-gyp install --fallback-to-build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the node-libcurl@2.2.0 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/jonashecht/.npm/_logs/2020-11-05T08_43_46_342Z-debug.log

I installed node via homebrew with brew install node. Versions are is:

node --version
v15.1.0
npm --version
6.14.8

Solution

  • The problem comes from newer versions of Xcode command line tools on recent MacOS versions.

    The crucial part in the log is:

      CXX(target) Release/obj.target/node_libcurl/src/node_libcurl.o
    clang: error: no such file or directory: '/usr/include'
    make: *** [Release/obj.target/node_libcurl/src/node_libcurl.o] Error 1
    

    As the node-libcurl docs state:

    newer versions of the Command Line Tools does not add the /usr/include folder by default. Check Xcode 10 release notes for details.

    To fix this, we need to tell npm install about the new location of /usr/include which is $(xcrun --show-sdk-path)/usr/include by setting the npm environment variable npm_config_curl_include_dirs like this:

    npm_config_curl_include_dirs="$(xcrun --show-sdk-path)/usr/include" npm install -g node-libcurl
    

    In my case where I wanted to install another npm library like insomnia-inso in the first place, you need to add both npm libraries to the command in order to do a successful installation:

    npm_config_curl_include_dirs="$(xcrun --show-sdk-path)/usr/include" npm install -g node-libcurl insomnia-inso
    

    Now the installation of insomnia-inso worked like a charm.