nodejs/node · error · GypError

xcodebuild returned unexpected results

Error message

xcodebuild returned unexpected results

What it means

Raised by XcodeVersion() when `xcodebuild -version` exits successfully (code 0) but produces fewer than two lines of output. Normally the command prints a version line and a build line; fewer than two lines indicates a broken or misconfigured Xcode installation. The function catches this and falls through to checking Command Line Tools instead, but raises this GypError before the fallback if the output is too sparse to parse.

Source

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

    # or like
    #    Xcode 3.2.6
    #    Component versions: DevToolsCore-1809.0; DevToolsSupport-1806.0
    #    BuildVersion: 10M2518
    # Convert that to ('0463', '4H1503') or ('0326', '10M2518').
    global XCODE_VERSION_CACHE
    if XCODE_VERSION_CACHE:
        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."""

View on GitHub (pinned to 1b2de5e052)

Solutions

  1. Reset the Xcode path: run `sudo xcode-select -r` (or `sudo xcode-select -s /Applications/Xcode.app/Contents/Developer`).
  2. Reinstall or repair Xcode from the Mac App Store, or run `xcode-select --install` for Command Line Tools.
  3. Verify with `xcodebuild -version` in a terminal — it should print two lines. If not, your Xcode install is broken.
  4. Accept the Xcode license if you recently installed it: `sudo xcodebuild -license accept`.

Example fix

# terminal fix
# before: xcode-select points to a stale path
xcode-select -p  # -> /wrong/path
# after
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
xcodebuild -version  # -> Xcode 15.0 / Build version 15A240d
Defensive patterns

Strategy: try-catch

Try / catch

from gyp.common import GypError
try:
    version = XcodeVersion()
except GypError as e:
    if 'unexpected results' in str(e):
        print('xcode-select path may be invalid; run: sudo xcode-select -r')
    raise

Prevention

When it happens

Trigger: GetStdoutQuiet(['xcodebuild', '-version']) succeeds but splitlines() yields 0 or 1 lines. This happens when xcodebuild exists but its output is empty or single-line due to a corrupted install.

Common situations: A bogus path set via `xcode-select -p` pointing to a stale or partial Xcode. A macOS upgrade that left xcodebuild in a half-installed state. Using a CLT-only install where xcodebuild is a stub.

Related errors


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