node.js 为什么 node-gyp 重建在 Mac OSX El Capitan 上失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38058386/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why is node-gyp rebuild failing on Mac OSX El Capitan
提问by roonie
I recently bought a mac, which uses Mac OSX El Capitan v10.11.4. Installed node with homebrew, and am using node v6.2.2 and npm v3.9.5. I'm getting an error with bcrypt during npm install, which I believe derives from a node-gyp rebuilderror. I also recently downloaded xcode-select(version 2343) and xcode(7.3.1) (in that order).
我最近买了一台 mac,它使用 Mac OSX El Capitan v10.11.4。使用自制软件安装节点,并使用节点 v6.2.2 和 npm v3.9.5。我在 bcrypt 期间遇到错误npm install,我认为这是由node-gyp rebuild错误引起的。我最近还下载了 xcode-select(version 2343) 和 xcode(7.3.1)(按此顺序)。
Here is the full error output after i run npm install:
这是我运行后的完整错误输出npm install:
https://gist.github.com/varunjayaraman/5734af617d616437cd5b3456b20bc503
https://gist.github.com/varunjayaraman/5734af617d616437cd5b3456b20bc503
Not sure what's going wrong. I come from linux land and do tend to be wary of not installing from source myself, so maybe that is the cause of these issues? Anyway, any advice would be super appreciated. I also saw this error springing up for others, but none of their solutions seemed to work (when i type xcode-select --print-path, I get /Applications/Xcode.app/Contents/Developer)
不知道出了什么问题。我来自 linux 领域并且确实倾向于警惕自己不从源代码安装,所以也许这就是这些问题的原因?无论如何,任何建议将不胜感激。我也看到其他人出现了这个错误,但他们的解决方案似乎都不起作用(当我输入时xcode-select --print-path,我得到了/Applications/Xcode.app/Contents/Developer)
回答by kdazzle
This one just bit me, too. There were a couple of different solutions, only one of which worked for me.
这个也咬了我一口。有几种不同的解决方案,其中只有一种对我有用。
First, make sure you have the XCode command line tools installed, as they say on their npm page.
首先,确保您安装了 XCode 命令行工具,正如他们在npm 页面上所说的那样。
1) The simplest solution, which of course didn't work (though it looks like it did for some people), is to just delete the ~/.node-gypdirectory. So might as well give that a shot, as well as deleting your node_modulesdir and doing another npm install.
1) 最简单的解决方案,当然这不起作用(尽管对某些人来说似乎是这样),就是删除~/.node-gyp目录。所以不妨试一试,以及删除你的node_modules目录并做另一个npm install.
2) Try uninstalling node-gyp and re-installing:
2) 尝试卸载 node-gyp 并重新安装:
sudo npm uninstall node-gyp -g
npm uninstall node-gyp
npm install
3) But what did the trick was a solution given in a node-gyp issue on github, where you have to install another version of node and do your npm install that way. It's easier than it sounds, but it's pretty gross:
3)但是诀窍是在 github 上的 node-gyp 问题中给出的解决方案,您必须在其中安装另一个版本的 node 并以这种方式安装 npm 。这比听起来容易,但它非常恶心:
sudo npm cache clean -f
sudo npm install -g n
sudo n 4.4.5
sudo npm install npm -g
sudo npm uninstall node-gyp -g
Then try running npm install.
然后尝试运行 npm install。
Hope that helps!
希望有帮助!
回答by metakungfu
Anytime i upgrade OSX to newer version, I get the same issue. Here is how i solve it every time:
每当我将 OSX 升级到较新版本时,都会遇到同样的问题。这是我每次解决它的方法:
sudo rm -rf /Library/Developer/CommandLineTools
xcode-select --install
That's it. Now next time you do npm install or yarn it'll work.
就是这样。现在,下次您执行 npm install 或 yarn 时,它会起作用。
回答by bhavinjr
Same issue I had after upgrading macOS
升级 macOS 后我遇到的相同问题
Update brew
更新酿造
brew update
Update X-Code
更新 X 代码
xcode-select --install
If needed, you may have to reset the path to X-Code
如果需要,您可能需要重置 X-Code 的路径
xcode-select --switch /Applications/Xcode.app
xcode-select --switch /Library/Developer/CommandLineTools
回答by TWright
Try looking at your python install.
尝试查看您的 python 安装。
I found a hint at the discussion here https://github.com/nodejs/node-gyp/issues/489#issuecomment-431447692.
我在这里的讨论中找到了一个提示https://github.com/nodejs/node-gyp/issues/489#issuecomment-431447692。
My python on my MacBook Pro is managed by Homebrew which installs binaries to
我的 MacBook Pro 上的 python 由 Homebrew 管理,它安装二进制文件到
/usr/local/bin
/usr/本地/bin
So I did the following in terminal:
所以我在终端中做了以下事情:
>$: npm config set python /usr/local/bin/python
>$: rm -rf node_modules
>$: npm i
回答by B.K
I had a similar issue and running the commands below fixed it for me
我有一个类似的问题,运行下面的命令为我修复了它
Install Xcode // if you dont have it installed already
Run sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
回答by Brent Washburne
If the node_modulescache was built with a recent version of Node, you may need to remove the cache, revert back and then reinstall the packages:
如果node_modules缓存是使用最新版本的 Node 构建的,您可能需要删除缓存,恢复,然后重新安装包:
rm -rf node_modules
nvm use 6
npm install
回答by Moobie
If you are using virtualenv for your python, you need to deactivate it or point npm to use the OS's own python 2 installation for node-gyp to work.
如果您为您的 python 使用 virtualenv,您需要停用它或指向 npm 以使用操作系统自己的 python 2 安装,以便 node-gyp 工作。
EDIT:
编辑:
Had another encounter with the same bug a few days ago. This time around node-gyp was notat fault. Apparently the module I was installing has a dependency on a very old version of node-gyp (v1), independent of the system's version (v3.8), which my version of node (v10) no longer supports. Since I did not need that module anymore, I removed it. Alternatively, you may wish to upgrade/downgrade/replace the offending module, or upgrade/downgrade your node. For the OP's case, the offending module was [email protected].
几天前又遇到了同样的错误。这一次 node-gyp没有错。显然,我正在安装的模块依赖于非常旧的 node-gyp (v1) 版本,独立于系统版本 (v3.8),我的 node (v10) 版本不再支持。由于我不再需要该模块,因此我将其删除。或者,您可能希望升级/降级/更换有问题的模块,或升级/降级您的节点。对于 OP 的案例,违规模块是 [email protected]。
回答by Rexcirus
After trying many solutions, what worked for me is uninstalling node, n, npm and nvm. The reinstalling nvm and installing node with it. I was following this answer:
在尝试了许多解决方案之后,对我有用的是卸载 node、n、npm 和 nvm。重新安装 nvm 并使用它安装节点。我正在关注这个答案:
How do I completely uninstall Node.js, and reinstall from beginning (Mac OS X)
如何完全卸载 Node.js,并从头开始重新安装 (Mac OS X)
Painful and long, but working.
痛苦而漫长,但有效。
回答by Yao Li
if you want to upgrade Node to 10 or above, you have to find dependencies out of date with Node 10 in package.json and upgrade these packages to newer stable version, then build (npm/yarn install).
如果你想将 Node 升级到 10 或更高版本,你必须在 package.json 中找到 Node 10 过时的依赖项并将这些包升级到更新的稳定版本,然后构建(npm/yarn install)。

