简体   繁体   English

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

[英]node-gyp rebuild fails on Mac OS High Sierra while npm install

I am getting following error in the terminal, while it tries to install one of package "node-expat".我在终端中遇到以下错误,同时它尝试安装“node-expat”包之一。 I have tried switching to different node version using nvm but still it is failing with same error.我曾尝试使用 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

I went ahead installing x-code as suggested on git hub page, on my machine and then it is giving following error,.我继续按照git hub页面上的建议在我的机器上安装x-code,然后出现以下错误。 Not sure how to debug further.不确定如何进一步调试。

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

I just got it fixed on my machine and my fellow colleagues machine.我刚把它固定在我的机器和我同事的机器上。

Followed the following steps to fix it on MacOS highSierra 10.13:按照以下步骤在 MacOS highSierra 10.13 上修复它:

  1. Downloaded command line tools (MacOS 10.13) for xcode and installed it.下载 xcode 的命令行工具 (MacOS 10.13) 并安装它。 Download it from " https://developer.apple.com/download/more/ "从“ https://developer.apple.com/download/more/ ”下载
  2. Installed xcode 10.0 from the app store.从应用商店安装了 xcode 10.0。 Opened xcode and went through the regular configuration xcode does in the initial start up.打开 xcode 并完成 xcode 在初始启动时所做的常规配置。
  3. After this it started giving "xcode-select" path issue as stated in the description above.在此之后,它开始给出“xcode-select”路径问题,如上面的描述中所述。 On running command " xcode-select --print-path " it was showing path as '/ Library/Developer/CommandLineTools', so i went ahead and tried " xcode-select --reset " after which the path changed to " /Applications/Xcode.app/Contents/Developer ".在运行命令“ xcode-select --print-path ”时,它显示路径为“/Library/Developer/CommandLineTools”,所以我继续尝试“ xcode-select --reset ”,之后路径更改为“ /Applications” /Xcode.app/Contents/Developer ”。 Immediately after it the build started working without any issues.在它之后,构建立即开始工作,没有任何问题。

Solution above mentioned by Luke worked partially for me (MacOS) but created another issue : gyp ERR! stack Error: Luke 上面提到的解决方案部分对我有用(MacOS),但产生了另一个问题: gyp ERR! stack Error: gyp ERR! stack Error: make failed with exit code: 2 which was solved by removing locked json file. gyp ERR! stack Error: make failed with exit code: 2已通过删除锁定的 json 文件解决。 Issue was created due to permission in MAC OS.问题是由于 MAC OS 中的许可而产生的。 So if you have xcode re-installed already, open terminal (command line) and type:因此,如果您已经重新安装了 xcode,请打开终端(命令行)并键入:

xcode-select --reset

then go to your project folder and remove: package-lock.json Now in terminal reinstall project :然后转到您的项目文件夹并删除: package-lock.json现在在终端中重新安装项目:

npm install

I hope this helps someone!我希望这可以帮助别人!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM