How to fix npm ERR! gyp ERR! stack Error: Command failed: xcode-select --print-path in npm
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.
Quick fix
Fixes gyp ERR!
xcode-select --print-path- Check current xcode-select path
- Reset xcode-select (quick fix)
- Install/reinstall Xcode Command Line Tools
- Switch to correct developer directory
xcode-select --print-pathnpm ERR! gyp ERR! stack Error: Command failed: xcode-select --print-path
What this error means
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.
Typical symptoms
- npm install stops with gyp ERR! stack Error message
- npm install fails when packages require native compilation
- Running `xcode-select --print-path` returns an empty string or error
- CI/CD pipelines fail during `npm install` on macOS runners
- Error appears after macOS system update
Common causes
- Xcode Command Line Tools are not installed on the system
- Command Line Tools were corrupted or partially uninstalled
- macOS system update invalidated the CLT installation
- Xcode developer directory path is set to wrong location
- Both full Xcode and CLT installed with conflicting paths
- node-gyp version mismatch with current Python version
How to fix "npm ERR! gyp ERR! stack Error: Command failed: xcode-select --print-path"
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.
Advanced notes
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.
Frequently asked questions
- What does "gyp ERR!" mean?
- 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.
- How do I fix "gyp ERR!"?
- 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.
- What causes "gyp ERR!"?
- Xcode Command Line Tools are not installed on the system Command Line Tools were corrupted or partially uninstalled macOS system update invalidated the CLT installation
- Is the "gyp ERR!" error serious?
- Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.
Official resources & further reading
- πnpm Official Documentation
- πnode-gyp Documentation(Official Docs)
- π¬Stack Overflow: node-gyp(Stack Overflow)
- πGitHub: node-gyp Issues(GitHub)