nodejs/node · error · GypError

No Xcode or CLT version detected!

Error message

No Xcode or CLT version detected!

What it means

Raised by XcodeVersion() as a last resort when neither `xcodebuild -version` nor CLTVersion() can determine a version. CLTVersion() checks pkgutil package receipts and softwareupdate history for Command Line Tools; if all of those return None, gyp has no way to know which compiler toolchain version to target and aborts.

Source

Thrown at tools/gyp/pylib/gyp/xcode_emulation.py:1512

        return XCODE_VERSION_CACHE
    version = ""
    build = ""
    try:
        version_list = GetStdoutQuiet(["xcodebuild", "-version"]).splitlines()
        # In some circumstances xcodebuild exits 0 but doesn't return
        # the right results; for example, a user on 10.7 or 10.8 with
        # a bogus path set via xcode-select
        # In that case this may be a CLT-only install so fall back to
        # checking that version.
        if len(version_list) < 2:
            raise GypError("xcodebuild returned unexpected results")
        version = version_list[0].split()[-1]  # Last word on first line
        build = version_list[-1].split()[-1]  # Last word on last line
    except (GypError, OSError):
        # Xcode not installed so look for XCode Command Line Tools
        version = CLTVersion()  # macOS Catalina returns 11.0.0.0.1.1567737322
        if not version:
            raise GypError("No Xcode or CLT version detected!")
    # Be careful to convert "4.2.3" to "0423" and "11.0.0" to "1100":
    version = version.split(".")[:3]  # Just major, minor, micro
    version[0] = version[0].zfill(2)  # Add a leading zero if major is one digit
    version = ("".join(version) + "00")[:4]  # Limit to exactly four characters
    XCODE_VERSION_CACHE = (version, build)
    return XCODE_VERSION_CACHE


# This function ported from the logic in Homebrew's CLT version check
def CLTVersion():
    """Returns the version of command-line tools from pkgutil."""
    # pkgutil output looks like
    #   package-id: com.apple.pkg.CLTools_Executables
    #   version: 5.0.1.0.1.1382131676
    #   volume: /
    #   location: /
    #   install-time: 1382544035
    #   groups: com.apple.FindSystemFiles.pkg-group

View on GitHub (pinned to 1b2de5e052)

Solutions

  1. Install Command Line Tools: run `xcode-select --install` and complete the GUI prompt.
  2. If Xcode is preferred, install it from the Mac App Store and run `sudo xcode-select -s /Applications/Xcode.app/Contents/Developer`.
  3. After install, accept the license: `sudo xcodebuild -license accept` (for Xcode) — gyp needs a working toolchain.
  4. Verify CLT detection by running `/usr/sbin/pkgutil --pkg-info com.apple.pkg.CLTools_Executables` and confirming a version line appears.

Example fix

# terminal fix
xcode-select --install
# then verify
xcrun --show-version
Defensive patterns

Strategy: validation

Validate before calling

# Pre-flight check: ensure a toolchain is detectable
import subprocess, shutil
if not shutil.which('xcodebuild'):
    print('No Xcode found. Install CLT: xcode-select --install')

Try / catch

from gyp.common import GypError
try:
    XcodeVersion()
except GypError as e:
    if 'No Xcode or CLT' in str(e):
        print('Install Command Line Tools: xcode-select --install')
    raise

Prevention

When it happens

Trigger: xcodebuild is unavailable or returns bad data (caught by except), then CLTVersion() returns None because none of the known pkgutil package IDs (com.apple.pkg.CLTools_Executables, etc.) match and softwareupdate history has no matching entry.

Common situations: Fresh macOS installation with neither Xcode nor Command Line Tools installed. After a major macOS upgrade that removed or invalidated CLT receipts. A system where pkgutil receipts are missing or corrupted.

Related errors


AI-assisted analysis of nodejs/node@1b2de5e052 (2026-08-13). Data as JSON: /api/errors/1c6fe527634016ed. Report an issue: GitHub.