NODE-GYP On macOS
NODE-GYP是什么
node下的gyp Google使用过很多处理平台无关的项目构建系统,比如Scons,CMake。在实际使用中这些并不能满足需求。开发复杂的应用程序时,在Mac上Xcode更加适合,而Windows上Visual Studio更是无二之选。gyp是为Chromium项目创建的项目生成工具,可以从平台无关的配置生成平台相关的Visual Studio、Xcode、Makefile的项目文件。这样一来我们就不需要花额外的时间处理每个平台不同的项目配置以及项目之间的依赖关系。
在macOS上的安装
前置需求
- node
- npm
- Python v3.6, v3.7, v3.8, or v3.9
- Xcode
官方描述:
ATTENTION: If your Mac has been upgraded to macOS Catalina (10.15), please read macOS_Catalina.md.
- Python v3.6, v3.7, v3.8, or v3.9
- Xcode
You also need to install theXCode Command Line Tools
by runningxcode-select --install
. Alternatively, if you already have the full Xcode installed, you can find them under the menuXcode -> Open Developer Tool -> More Developer Tools...
. This step will installclang
,clang++
, andmake
.
安装命令
npm install -g node-gyp
不安装Xcode健康食用node-gyp的方案
为什么不安装Xcode?
Xcode体积庞大,约7-8G,然而很多时候用不到,我几乎不用
安装CommandLineTools,然后npm install
但是在install的时候会报错,大致有两个原因
- Xcode问题
解决办法:
1.删除已经安装的CommandLineTools
$ sudo rm -rf $(xcode-select -p)
2.重新安装
$ sudo xcode-select --install
同意条款选择同意,会提示系统更新一并同意。
- Python版本问题
官方说明Python版本必须是
v3.6, v3.7, v3.8, or v3.9
macOS系统自带Python版本为2.7,升级版本可看macOS自带Python2.7版本升级