Is node-gyp (Node.js native addon build tool) failing during yarn install or npm install? If your macOS got upgraded to Catalina (10.15) recently, then you will find the fix right here.

Explainer Video:

Sample Error

abhijit@macpro gulp-responsive % npm install --save-dev gulp-responsive
> [email protected] install /Users/abhijit/workspace/image-optimization/gulp-responsive/node_modules/sharp
> (node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)
info sharp Detected globally-installed libvips v8.9.2
info sharp Building from source via node-gyp
gyp: No Xcode or CLT version detected!
gyp ERR! configure error 
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:351:16)

So, what went wrong?

node-gyp uses XCode Command Line Tools for macOS.

Both upgrading to macOS Catalina and running a Software Update in Catalina may cause normal node-gyp installations to fail. This might manifest as the following error during npm install:

gyp: No Xcode or CLT version detected!
Reference: Installation notes for macOS Catalina (v10.15)

Check MacOS version

Run sw_vers in terminal to check your MacOS version. Actually, if ProductVersion is less then 10.15, then fix of this post may not be applicable.

abhijit@macpro ~ % sw_vers
ProductName:	Mac OS X
ProductVersion:	10.15.6
BuildVersion:	19G2021

How to fix?

Reinstall the XCode Command Line Tools.

  1. Remove the XCode Command Line Tools.
    abhijit@macpro gulp-responsive % xcode-select --print-path
    /Library/Developer/CommandLineTools
    abhijit@macpro gulp-responsive % sudo rm -r -f /Library/Developer/CommandLineTools
    Password:
    
    
    or
    abhijit@macpro gulp-responsive % sudo rm -rf $(xcode-select -print-path)
    Password:
    
    
  2. Install the XCode Command Line Tools.
    abhijit@macpro gulp-responsive % xcode-select --install
    xcode-select: note: install requested for command line developer tools
    
    Click "Install" button in the wizard, accept "License Agreement" and click "Done" once the software is installed.

Acid Test

If the below acid test passes, we are good to go.

abhijit@macpro ~ % curl -sL https://github.com/nodejs/node-gyp/raw/master/macOS_Catalina_acid_test.sh | bash
Command Line Tools version: 12.0.0.0.1.1597368733

Verify

Finally, we'll run the initial npm install that failed for us.

bhijit@macpro gulp-responsive % npm install --save-dev gulp-responsive
> [email protected] install /Users/abhijit/workspace/image-optimization/gulp-responsive/node_modules/gulp-responsive/node_modules/sharp
> (node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)
info sharp Detected globally-installed libvips v8.9.2
info sharp Building from source via node-gyp
  TOUCH Release/obj.target/libvips-cpp.stamp
  CXX(target) Release/obj.target/sharp/src/common.o
  CXX(target) Release/obj.target/sharp/src/metadata.o
  CXX(target) Release/obj.target/sharp/src/stats.o
  CXX(target) Release/obj.target/sharp/src/operations.o
  CXX(target) Release/obj.target/sharp/src/pipeline.o
  CXX(target) Release/obj.target/sharp/src/sharp.o
  CXX(target) Release/obj.target/sharp/src/utilities.o
  SOLINK_MODULE(target) Release/sharp.node
npm WARN [email protected] No repository field.

+ [email protected]
added 43 packages from 120 contributors and audited 389 packages in 23.309s

References