无法在没有Xcode的Mac上进行npm安装?

时间:2019-04-02 20:32:45

标签: node.js xcode macos npm node-gyp

我正在尝试在Mac机器上运行npm 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 "/Users/mac/.nvm/versions/node/v8.11.3/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py", line 16, in <module>
    sys.exit(gyp.script_main())
  File "/Users/mac/.nvm/versions/node/v8.11.3/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 545, in script_main
    return main(sys.argv[1:])
  File "/Users/mac/.nvm/versions/node/v8.11.3/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 538, in main
    return gyp_main(args)
  File "/Users/mac/.nvm/versions/node/v8.11.3/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 523, in gyp_main
    generator.GenerateOutput(flat_list, targets, data, params)
  File "/Users/mac/.nvm/versions/node/v8.11.3/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py", line 2170, in GenerateOutput
    part_of_all=qualified_target in needed_targets)
  File "/Users/mac/.nvm/versions/node/v8.11.3/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py", line 795, in Write
    self.Pchify))
  File "/Users/mac/.nvm/versions/node/v8.11.3/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py", line 1190, in WriteSources
    cflags = self.xcode_settings.GetCflags(configname)
  File "/Users/mac/.nvm/versions/node/v8.11.3/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py", line 551, in GetCflags
    archs = self.GetActiveArchs(self.configname)
  File "/Users/mac/.nvm/versions/node/v8.11.3/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py", line 420, in GetActiveArchs

我知道我可以通过安装Xcode并设置路径来摆脱这种情况。但是以某种方式我不想使用Xcode。我已经通过

安装了命令行工具
xcode-select --install

并设置它的路径,但仍然出现此错误。有任何想法吗?

1 个答案:

答案 0 :(得分:-2)

在之前安装NPM之前,不能通过命令行在计算机上安装NPM。简而言之,您只能通过命令行更新NPM,而最初无法安装。从以下位置下载Node.JS:NodeJs。它带有NPM。如果正在运行全局(-g)安装,请尝试SUDO。