微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在MacOS Catalina上,node-libcurl安装失败:clang:错误:无此类文件或目录:'/ usr / include'

如何解决在MacOS Catalina上,node-libcurl安装失败:clang:错误:无此类文件或目录:'/ usr / include'

我只是想在insomnia-inso有依赖性的Mac(Catalina)上安装node-libcurl,并出现以下错误

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

我使用node通过自制程序安装了brew install node。版本是:

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

解决方法

问题来自最新MacOS版本上的Xcode命令行工具的较新版本。

日志中的关键部分是:

  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

作为node-libcurl docs state

命令行工具的较新版本未添加/ usr / include 文件夹默认情况下。查看Xcode 10 release notes了解详情。

要解决此问题,我们需要通过设置npm环境变量npm install来告知/usr/include $(xcrun --show-sdk-path)/usr/include的新位置npm_config_curl_include_dirs

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

在我想首先安装另一个insomnia-inso之类的npm库的情况下,您需要将两个npm库都添加到命令中才能成功安装:

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

现在安装insomnia-inso就像是一种魅力。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。