This error occurs when building native Node.js modules on macOS and you haven't accepted the Xcode license agreement. The fix requires running a simple command with admin privileges to accept the license.
Fixes npm ERR! gyp ERR! stack Error: Agreeing to the Xcode license requires admin privileges
sudo xcodebuild -license acceptsudo xcodebuild -license acceptnpm ERR! gyp ERR! stack Error: Agreeing to the Xcode license requires admin privileges
This error appears when npm tries to compile native Node.js modules (like node-gyp, bcrypt, or sharp) on macOS, but the Xcode Command Line Tools license hasn't been accepted yet. macOS requires explicit acceptance of Apple's license agreement before development tools can be used. Native modules that need compilation rely on these tools, so the build process fails until the license is accepted. This commonly happens after installing or updating Xcode, upgrading macOS, or on fresh developer machine setups.
Run the following command to accept the Xcode license agreement:
sudo xcodebuild -license acceptYou'll need to enter your admin password. This accepts the license non-interactively.
If you want to read the license first:
sudo xcodebuild -licenseScroll through the license text (press Space), then type "agree" at the prompt.
Make sure the Command Line Tools are properly installed:
xcode-select --installIf they're already installed, you'll see a message saying so. Otherwise, follow the GUI prompts.
After accepting the license, retry your installation:
npm installNative modules should now compile successfully.
If you have multiple Xcode versions installed, ensure the correct one is selected:
sudo xcode-select -s /Applications/Xcode.app/Contents/DeveloperFor CI/CD pipelines on macOS, include the license acceptance step in your setup:
- run: sudo xcodebuild -license acceptIf you only need Command Line Tools (not full Xcode), you can install them standalone and they have a simpler license process. However, some native modules may still require full Xcode.