48

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
  • 763
  • 1
  • 9
  • 15
  • 1
    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

14 Answers14

64

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/

magicgregz
  • 7,471
  • 3
  • 35
  • 27
  • 51
    Just updated to 10.15.4 & had the same issue - I googled & found again my own answer which worked... awesome. – magicgregz Apr 08 '20 at 20:36
  • 2
    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
  • 2
    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. – magicgregz Dec 22 '20 at 21:56
  • 1
    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
  • Should note to any future readers this is a force recursive delete. No warning will be prompted and no recovery offered. Take care – Lex Jul 17 '23 at 12:44
32

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
  • 4,190
  • 3
  • 24
  • 27
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
  • 12,904
  • 4
  • 60
  • 82
2

I have a simple solution. If the xcode-sellect is installed try running sudo xcode-select --reset

Narek Tootikian
  • 1,323
  • 2
  • 9
  • 15
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,663
  • 13
  • 19
1

For anyone who tried reinstalling Xcode tools yet the same issue persists.

You will have to go following file:

~/.node-gyp/<your_node_version_here>/include/node/common.gypi

Note: Make sure to change <you_node_version_here> to your node version like:

~/.node-gyp/16.13.1/include/node/common.gypi You can find node version using node -v

Inside search for key MACOSX_DEPLOYMENT_TARGET and change it's value to your current os version like mine is 11.3.1 and you will be good to go. You can find version in

about this mac

option in drop down of mac logo

Abdulmoiz Ahmer
  • 1,953
  • 17
  • 39
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,445
  • 14
  • 21
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
  • 2,071
  • 1
  • 25
  • 24
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,853
  • 18
  • 25
0

I had a similar issue and running the commands below fixed it for me

  1. Install xcode
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
Pants
  • 2,563
  • 1
  • 20
  • 34
B.K
  • 847
  • 10
  • 6
0

I had a similar issue.

A lot of folks have recommended that you install Xcode, and point xcode-select to the /Applications/Xcode.app/Contents/Developer. However, there is one more step.

That is to confirm that the /Applications/Xcode.app/Contents/Developer folder has SDK version corresponding to the MacOS version your actual computer is running on.

If it does not, go into /Library/Developer/CommandLineTools and copy that over.

Winston Du
  • 340
  • 2
  • 9
0

You need to re-install XCode Tool in order to compile your codes in your machine: * xcode-select -print-path * sudo xcode-select --reset * xcode-select -print-path

Here's the main link you can install it on MacOS: https://github.com/nodejs/node-gyp/blob/main/macOS_Catalina.md

Rasikh
  • 5
  • 1
  • 2
0

In my case (mac M1) helped:

  1. clean npm cache npm cache clean –force
  2. switch node to v12 (I'am using nvm)nvm use 12
  3. run npm install
  4. then switch to your current node e.g. v16 nvm use 16
  5. again run npm install
  6. restart your IDE
Jakub Kurdziel
  • 3,216
  • 2
  • 12
  • 22
0

My case was that I used VS Code terminal
and my default terminal was zsh

After I changed it to bash, all the problem just solved

CHOI
  • 114
  • 1
  • 5