This error occurs when npm tries to build native modules during package installation but cannot find or access Xcode Command Line Tools on macOS. Node-gyp requires Xcode CLT to compile C/C++ dependencies.
Fixes gyp ERR!
xcode-select --print-pathxcode-select --print-pathnpm ERR! gyp ERR! stack Error: Command failed: xcode-select --print-path
When you run `npm install`, some packages contain native C/C++ code that must be compiled. Node-gyp handles this compilation. The error means node-gyp tried to query the Xcode developer directory path but failed. This typically happens because Xcode Command Line Tools are not installed, the developer directory path is misconfigured, or a macOS update invalidated the previous installation.
First, verify what path xcode-select is using:
xcode-select --print-pathIf this returns an error or empty string, CLT is missing.
The simplest solution is resetting xcode-select:
sudo xcode-select --resetVerify it worked:
xcode-select --print-pathShould show /Applications/Xcode.app/Contents/Developer or /Library/Developer/CommandLineTools. Now try npm install again.
If reset didn't work, reinstall CLT:
sudo rm -rf /Library/Developer/CommandLineTools
xcode-select --installA popup window will appear. Click 'Install' and wait for completion (10-20 minutes).
If you have full Xcode.app installed, point xcode-select to it:
sudo xcode-select --switch /Applications/Xcode.app/Contents/DeveloperVerify:
xcode-select --print-pathIf automatic installer fails:
1. Visit https://developer.apple.com/download/all/
2. Sign in with your Apple ID
3. Search for 'Command Line Tools'
4. Download the .dmg matching your macOS version
5. Open the .dmg and run the installer
6. Verify with xcode-select --print-path
7. Retry npm install
If using Python 3.12+, you need node-gyp 10+:
npm install -g node-gyp@latest
npm config set node_gyp "/usr/local/lib/node_modules/node-gyp/bin/node-gyp.js"Retry npm install.
The xcode-select tool manages the developer directory path used by build tools. After macOS updates (especially major version upgrades), the developer directory path can become stale, requiring reset or reinstall. Most cases can be resolved with sudo xcode-select --reset; full Xcode installation is rarely necessary unless you develop for iOS. If you're in an organization with security software, xcode-select --install may fail—in that case, manual download is required.