mac中node-gpy的安装
2020-01-19 本文已影响0人
zdmission
问题:
前端项目,执行npm install安装包的时候会出现node-gyp的一下错误,如下所示
npm install
......
No receipt for 'com.apple.pkg.CLTools_Executables' found at '/'.
No receipt for 'com.apple.pkg.DeveloperToolsCLILeo' found at '/'.
No receipt for 'com.apple.pkg.DeveloperToolsCLI' found at '/'.
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 (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:351:16)
gyp ERR! stack at ChildProcess.emit (events.js:210:5)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
gyp ERR! System Darwin 19.2.0
gyp ERR! command "/usr/local/Cellar/node/10.16.0/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/*/Project/*/node_modules/fsevents
gyp ERR! node -v v10.16.0
gyp ERR! node-gyp -v v6.0.1
gyp ERR! not ok
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.11 (node_modules/fsevents):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.11 install: `node-gyp rebuild`
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1
added 198 packages from 116 contributors and audited 362 packages in 6.487s
安装参考 https://github.com/nodejs/node-gyp#on-macos,如果你的mac已经升级到macOS Catalina (10.15)及以上,请参考https://github.com/nodejs/node-gyp/blob/master/macOS_Catalina.md
- 1.在App Store中搜索安装xcode
- 2.确保xcode命令行工具安装正常,通过如下命令验证
/usr/sbin/pkgutil --packages | grep CL
// com.apple.pkg.CLTools_Executables应该列出。如果不是,则此测试失败。
// 有输出信息,验证通过,比如
/ **
com.apple.pkg.CLTools_Executables
com.apple.pkg.CLTools_SDK_macOS1015
com.apple.pkg.CLTools_SDK_macOS1014
com.apple.pkg.CLTools_macOS_SDK
*/
/usr/sbin/pkgutil --pkg-info com.apple.pkg.CLTools_Executables
// version: 11.0.0(或更高版本)应列出。如果不是,则此测试失败。
// 有输出信息,验证通过,比如
/ **
package-id: com.apple.pkg.CLTools_Executables
version: 11.3.1.0.1.1576735732
volume: /
location: /
install-time: 1579417091
groups: com.apple.FindSystemFiles.pkg-group
*/
// 如果两项测试均成功,则说明您已完成!您应该已经准备好安装node-gyp。
// 如果任何一项测试失败,则说明您的Xcode命令行工具安装存在问题
- 3.检查是否安装Command Line Tools,在终端输入
// 该命令也是安装命令
xcode-select --install
// xcode-select: error: command line tools are already installed, use "Software Update" to install updates,表示已经安装过了
// 删除重新安装
sudo rm -rf /Library/Developer/CommandLineTools
// 执行安装,此过程需要花费几分钟
xcode-select --install
可以参考 Xcode使用之安装Xcode Command Line Tools
- 4.以上过程完成之后,重复第2步验证
如果以上问题通过,再次执行npm install就会安装成功了