I have been facing this issue on my Mac OS Catalina recently where I am unable to install certain Node.js packages using npm. The installation usually fails whenever there is a dependency on node-gyp.

node-gyp is a cross-platform command-line tool written in Node.js for compiling native addon modules for Node.js.


After searching on internet and trying few different solutions I have found a reliable approach to resolve this issue. Here you go:

  1. Remove the command line tools from your Mac
sudo rm -rf  /Library/Developer/CommandLineTools

2. Install the latest command line utility from XCode

xcode-select --install

And it should work now!

This error usually comes up when you upgrade your OS to a newer version. Let me know in the comments if this solution or any other approach worked for you. Cheers!