Why is node-gyp rebuild failing on Mac OSX El Capitan

烈酒焚心 提交于 2019-12-01 15:05:08

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.

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-gyp directory. So might as well give that a shot, as well as deleting your node_modules dir and doing another npm install.

2) Try uninstalling node-gyp and re-installing:

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:

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.

Hope that helps!

If the node_modules cache was built with a recent version of Node, you may need to remove the cache, revert back and then reinstall the packages:

rm -rf node_modules
nvm use 6
npm install

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.


EDIT:

Had another encounter with the same bug a few days ago. This time around node-gyp was not at 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 bcrypt@0.8.5.

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:

How do I completely uninstall Node.js, and reinstall from beginning (Mac OS X)

Painful and long, but working.

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).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!