其他 2020-08-12 13:25:50

问题

使用yarn或者npm安装依赖经常会出现这个错误:

gyp: No Xcode or CLT version detected!
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack at ChildProcess.onCpExit (/Users/alfred/.nvm/versions/node/v10.15.2/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:345:16)
gyp ERR! stack at ChildProcess.emit (events.js:189:13)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:248:12)
gyp ERR! System Darwin 18.0.0
gyp ERR! command \"/Users/alfred/.nvm/versions/node/v10.15.2/bin/node\" \"/Users/alfred/.nvm/versions/node/v10.15.2/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js\" \"rebuild\"
gyp ERR! cwd /Users/alfred/workspace/geely/service-number-miniprogram/node_modules/fsevents
gyp ERR! node -v v10.15.2
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok"

提示Xcode或者CLT未安装。

解决

尝试解决

我们可以先尝试使用以下命令执行安装:

sudo xcode-select --install

如果安装xcode或CLT出现:

xcode-select: error: command line tools are already installed, use "Software Update" to install updates

就执行以下命令先删除旧版本的xcode-select,再重新安装

sudo rm -rf /Library/Developer/CommandLineTools
sudo xcode-select --install

如果安装xcode或CLT出现: http://alicdn.miaokefu.com/blogs/xcode下载失败.jpg

可以去Apple 官网下载最新版本的Command Line Tools手动安装 http://alicdn.miaokefu.com/blogs/command-line-tools.jpg

确认安装完成

命令行输入brew config确认是否安装成功

macOS: 10.15.6-x86_64
CLT: 11.5.0.0.1.1588476445
Xcode: N/A
CLT headers: 11.5.0.0.1.1588476445

可以看到CLT 11.5版本安装成功