在安装npm时,Mac OS High Sierra上的node-gyp重建失败

时间:2018-11-01 05:17:01

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

在尝试安装软件包“ node-expat”之一时,终端出现以下错误。我尝试使用nvm切换到不同的节点版本,但仍然失败,并出现相同的错误。

gyp ERR! command "node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /usr/local/lib/node_modules/node-expat
npm ERR! node v6.5.0
npm ERR! npm  v3.10.3
npm ERR! code ELIFECYCLE
npm ERR! node-expat@2.0.0 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the node-expat@2.0.0 install script 'node-gyp rebuild'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the node-expat package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs node-expat
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls node-expat
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     c:\<redacted>\npm-debug.log

我按照我的计算机上git hub页面上的建议继续安装x代码,然后出现以下错误。不确定如何进一步调试。

xcode-select: error: tool 'xcodebuild' requires Xcode, 
but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance

2 个答案:

答案 0 :(得分:4)

我刚刚将它固定在我的机器和同事的机器上。

按照以下步骤在MacOS highSierra 10.13上进行修复:

  1. 为xcode下载并安装了命令行工具(MacOS 10.13)。 从“ https://developer.apple.com/download/more/”下载它
  2. 从应用程序商店安装了xcode 10.0。打开xcode,并在初次启动时进行了xcode的常规配置。
  3. 此后,它开始提供“ xcode-select”路径问题,如上面的描述中所述。在运行命令“ xcode-select --print-path ”时,路径显示为“ / Library / Developer / CommandLineTools”,因此我继续尝试“ xcode-select --reset” ”,然后路径更改为“ /Applications/Xcode.app/Contents/Developer ”。 生成后立即开始运行,没有任何问题。

答案 1 :(得分:1)

Luke提到的上述解决方案部分对我有用(MacOS),但又产生了另一个问题: gyp ERR! stack Error: make failed with exit code: 2可以通过删除锁定的json文件来解决。由于MAC OS中的权限,已创建问题。因此,如果您已经重新安装了xcode,请打开终端(命令行)并输入:

xcode-select --reset

然后转到您的项目文件夹并删除: package-lock.json 现在在终端中重新安装项目:

npm install

我希望这对某人有帮助!