错误信息
➜ hs-xxx git:(master) cnpm install
xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance
xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance
Traceback (most recent call last):
File "/usr/local/lib/node_modules/cnpm/node_modules/node-gyp/gyp/gyp_main.py", line 16, in <module>
sys.exit(gyp.script_main())
File "/usr/local/lib/node_modules/cnpm/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 545, in script_main
return main(sys.argv[1:])
File "/usr/local/lib/node_modules/cnpm/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 538, in main
return gyp_main(args)
File "/usr/local/lib/node_modules/cnpm/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 523, in gyp_main
generator.GenerateOutput(flat_list, targets, data, params)
File "/usr/local/lib/node_modules/cnpm/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py", line 2170, in GenerateOutput
part_of_all=qualified_target in needed_targets)
File "/usr/local/lib/node_modules/cnpm/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py", line 795, in Write
self.Pchify))
File "/usr/local/lib/node_modules/cnpm/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py", line 1190, in WriteSources
cflags = self.xcode_settings.GetCflags(configname)
File "/usr/local/lib/node_modules/cnpm/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py", line 551, in GetCflags
archs = self.GetActiveArchs(self.configname)
File "/usr/local/lib/node_modules/cnpm/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py", line 420, in GetActiveArchs
xcode_archs_default = GetXcodeArchsDefault()
File "/usr/local/lib/node_modules/cnpm/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py", line 118, in GetXcodeArchsDefault
xcode_version, _ = XcodeVersion()
File "/usr/local/lib/node_modules/cnpm/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py", line 1265, in XcodeVersion
version = re.match(r'(\d\.\d\.?\d*)', version).groups()[0]
AttributeError: 'NoneType' object has no attribute 'groups'
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/cnpm/node_modules/node-gyp/lib/configure.js:336: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 19.3.0
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/cnpm/node_modules/npminstall/node-gyp-bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/ddy/workspace/workspace_ecoin/hs-airdrop/node_modules/_goosig@0.6.0@goosig
gyp ERR! node -v v10.15.3
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
✖ Install fail! Error: post install error, please remove node_modules before retry!
Run "sh -c node-gyp rebuild" error, exit code 1
Error: post install error, please remove node_modules before retry!
Run "sh -c node-gyp rebuild" error, exit code 1
at ChildProcess.proc.on.code (/usr/local/lib/node_modules/cnpm/node_modules/runscript/index.js:74:21)
at ChildProcess.emit (events.js:189:13)
at maybeClose (internal/child_process.js:970:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
npminstall version: 3.3.0
npminstall args: /usr/local/bin/node /usr/local/lib/node_modules/cnpm/node_modules/npminstall/bin/install.js --china --userconfig=/Users/ddy/.cnpmrc --disturl=https://npm.taobao.org/mirrors/node --registry=https://registry.npm.taobao.org
报错原因
当CommandLineTools
先于Xcode
安装时,会出现xcode-select
的开发者目录指向了/Library/Developer/CommandLineTools
路径,实际应当指向/Applications/Xcode.app/Contents/Developer
路径。
解决办法
1、安装Xcode
,如果没有安装的话。https://appstore.com/mac/apple/xcode ,安装完成后需要注意检查Xcode是否安装到了 /Applications
目录下。 (而不是/Users/{user}/Applications
).
说明:正确的Xcode安装路径如下
Xcode: /Applications/Xcode.app/Contents/Developer Xcode-beta: /Applications/Xcode-beta.app/Contents/Developer
2、重新安装xcode-select
并将其指向Xcode
的开发者目录路径
#删除
$ sudo rm -rf $(xcode-select -p)
#重装
$ sudo xcode-select --install
使用以下命令将xcode-select
指向Xcode开发者目录
$ sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
执行完以上操作后,报错问题得到了解决。依赖能够顺利安装了。