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

7

在尝试安装“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

我按照 GitHub 页面上的建议,在我的机器上安装了 Xcode,但是它出现了以下错误。不确定该如何进一步调试。
xcode-select: error: tool 'xcodebuild' requires Xcode, 
but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance
2个回答

6

我刚刚在我的机器和同事的机器上修复好了它。

按照以下步骤在MacOS High Sierra 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”。立即之后,构建开始无任何问题。

3

我在MacOS上尝试Luke提出的解决方法,但只部分生效,并引发了另一个问题:gyp ERR! stack Error:make退出代码为2。这个问题可以通过删除锁定的json文件来解决。这个问题是由于MAC OS的权限问题导致的。因此,如果您已经重新安装了Xcode,请打开终端(命令行)并键入:

xcode-select --reset

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

npm install

我希望这能对某些人有所帮助!


我的建议是基于我的个人经历(我遇到了同样的问题,并按照上述方法解决了它)。因此,这不是一个猜测。如果您要给出负面评价,请留下评论,以便我知道您为什么这样做,并且如果有理由的话,请删除我的评论。否则,我们会误导那些可能遇到与我相同情况的人。 - StefaDesign

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接