{"record":{"id":"817f06d868c265a2","repo":"nodejs/node","slug":"xcodebuild-returned-unexpected-results","errorCode":null,"errorMessage":"xcodebuild returned unexpected results","messagePattern":"xcodebuild returned unexpected results","errorType":"exception","errorClass":"GypError","httpStatus":null,"severity":"error","filePath":"tools/gyp/pylib/gyp/xcode_emulation.py","lineNumber":1505,"sourceCode":"    # or like\n    #    Xcode 3.2.6\n    #    Component versions: DevToolsCore-1809.0; DevToolsSupport-1806.0\n    #    BuildVersion: 10M2518\n    # Convert that to ('0463', '4H1503') or ('0326', '10M2518').\n    global XCODE_VERSION_CACHE\n    if XCODE_VERSION_CACHE:\n        return XCODE_VERSION_CACHE\n    version = \"\"\n    build = \"\"\n    try:\n        version_list = GetStdoutQuiet([\"xcodebuild\", \"-version\"]).splitlines()\n        # In some circumstances xcodebuild exits 0 but doesn't return\n        # the right results; for example, a user on 10.7 or 10.8 with\n        # a bogus path set via xcode-select\n        # In that case this may be a CLT-only install so fall back to\n        # checking that version.\n        if len(version_list) < 2:\n            raise GypError(\"xcodebuild returned unexpected results\")\n        version = version_list[0].split()[-1]  # Last word on first line\n        build = version_list[-1].split()[-1]  # Last word on last line\n    except (GypError, OSError):\n        # Xcode not installed so look for XCode Command Line Tools\n        version = CLTVersion()  # macOS Catalina returns 11.0.0.0.1.1567737322\n        if not version:\n            raise GypError(\"No Xcode or CLT version detected!\")\n    # Be careful to convert \"4.2.3\" to \"0423\" and \"11.0.0\" to \"1100\":\n    version = version.split(\".\")[:3]  # Just major, minor, micro\n    version[0] = version[0].zfill(2)  # Add a leading zero if major is one digit\n    version = (\"\".join(version) + \"00\")[:4]  # Limit to exactly four characters\n    XCODE_VERSION_CACHE = (version, build)\n    return XCODE_VERSION_CACHE\n\n\n# This function ported from the logic in Homebrew's CLT version check\ndef CLTVersion():\n    \"\"\"Returns the version of command-line tools from pkgutil.\"\"\"","sourceCodeStart":1487,"sourceCodeEnd":1523,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/tools/gyp/pylib/gyp/xcode_emulation.py#L1487-L1523","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Reset the Xcode path: run `sudo xcode-select -r` (or `sudo xcode-select -s /Applications/Xcode.app/Contents/Developer`).","Reinstall or repair Xcode from the Mac App Store, or run `xcode-select --install` for Command Line Tools.","Verify with `xcodebuild -version` in a terminal — it should print two lines. If not, your Xcode install is broken.","Accept the Xcode license if you recently installed it: `sudo xcodebuild -license accept`."],"exampleFix":"# terminal fix\n# before: xcode-select points to a stale path\nxcode-select -p  # -> /wrong/path\n# after\nsudo xcode-select -s /Applications/Xcode.app/Contents/Developer\nxcodebuild -version  # -> Xcode 15.0 / Build version 15A240d","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"from gyp.common import GypError\ntry:\n    version = XcodeVersion()\nexcept GypError as e:\n    if 'unexpected results' in str(e):\n        print('xcode-select path may be invalid; run: sudo xcode-select -r')\n    raise","preventionTips":["After every macOS upgrade, run `sudo xcode-select -r` to reset the developer path.","Verify `xcodebuild -version` prints two lines before running gyp on macOS."],"tags":["xcode","gyp","macos","environment"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}