32

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 rebuild error. I also recently downloaded xcode-select(version 2343) and xcode(7.3.1) (in that order).

Here is the full error output after i run npm install:

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)

roonie
  • 583
  • 1
  • 7
  • 13
  • I regularly see issue appearing that have to do with Homebrew installations of Node that are solved by using the [official installer](https://nodejs.org/en/download/current/). Might be worth a try. – robertklep Jun 27 '16 at 16:23

8 Answers8

26

Anytime i upgrade OSX to newer version, I get the same issue. Here is how i solve it every time:

sudo rm -rf  /Library/Developer/CommandLineTools
xcode-select --install

That's it. Now next time you do npm install or yarn it'll work.

PS: Sometimes you won't be able to install the command line tool through Xcode-select, for example if you are on beta. In that case, you should be able to install it manually from here: https://developer.apple.com/download/more/

metakungfu
  • 6,073
  • 2
  • 33
  • 24
  • 17
    Just updated to 10.15.4 & had the same issue - I googled & found again my own answer which worked... awesome. – metakungfu Apr 08 '20 at 20:36
  • I'm having issues on Big Sur and this fix does not seem to work. Any issues for you? Maybe I need to update python or something cause I'm seeing it reference python in the error trace? – thomallen Dec 18 '20 at 19:01
  • I'm also on BigSur - I had the same issue & the same fix worked. Though it came back a couple times when I was updating to the latest beta release. You should try again. I'm not sure if python is related. – metakungfu Dec 22 '20 at 21:56
  • Yeah we had multiple devs deal with this issue this week so we just removed bcrypt from our project which was the only package using node-gyp. – thomallen Dec 30 '20 at 23:57
  • this worked for me, thank you very much. – cristianojeda Apr 29 '21 at 02:22
23

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!

kdazzle
  • 3,943
  • 3
  • 21
  • 25
2

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
Brent Washburne
  • 11,417
  • 4
  • 51
  • 70
1

Same issue I had after upgrading macOS

Update brew

brew update

Update X-Code

xcode-select --install

If needed, you may have to reset the path to X-Code

xcode-select --switch /Applications/Xcode.app
xcode-select --switch /Library/Developer/CommandLineTools
bhavinjr
  • 1,482
  • 9
  • 16
0

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.

Moobie
  • 1,267
  • 13
  • 19
0

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

Yao Li
  • 1,523
  • 1
  • 19
  • 22
0

Try looking at your python install.

I found a hint at the discussion here https://github.com/nodejs/node-gyp/issues/489#issuecomment-431447692.

My python on my MacBook Pro is managed by Homebrew which installs binaries to

/usr/local/bin

So I did the following in terminal:

>$: npm config set python /usr/local/bin/python
>$: rm -rf node_modules
>$: npm i
TWright
  • 1,793
  • 17
  • 24
0

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
B.K
  • 681
  • 7
  • 5