node-gyp: Problems on Mavericks with only Command Line Tools installed

I have installed the Command Line Tools:

$ xcode-select --print-path
/Library/Developer/CommandLineTools

However, when anything tries to use node-gyp, I get the following error:

$ npm install bcrypt
npm http GET https://registry.npmjs.org/bcrypt
npm http 304 https://registry.npmjs.org/bcrypt
npm http GET https://registry.npmjs.org/bindings/1.0.0
npm http 304 https://registry.npmjs.org/bindings/1.0.0

> bcrypt@0.7.7 install /Users/Oliver/Development/sbscribe/node_modules/bcrypt
> node-gyp rebuild

xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance

gyp: Error 1 running xcodebuild
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:424:16)
gyp ERR! stack     at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:789:12)
gyp ERR! System Darwin 13.0.0
gyp ERR! command "node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/Oliver/Development/sbscribe/node_modules/bcrypt
gyp ERR! node -v v0.10.21
gyp ERR! node-gyp -v v0.10.10
gyp ERR! not ok
npm ERR! weird error 1
npm ERR! not ok code 0

On Mountain Lion it was possible to use this without installing the whole of Xcode, rather just the Command Line Tools. Is it possible to do this on Mavericks? How can I get it working?

N.B. This is on a clean install of Mavericks.

About this issue

  • Original URL
  • State: closed
  • Created 11 years ago
  • Comments: 78 (6 by maintainers)

Most upvoted comments

To re-iterate @Poohblah’s solution:

The Error

xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance

The Solution

  1. Run which xcodebuild in the terminal. If it gives no output, continue to step 2. If it gives output, then this solution will not work for you.

  2. Create a file /usr/local/bin/xcodebuild. In that file, use your favourite editor to add the contents:

    #!/bin/bash
    
    exit 0
    
  3. Save that file, and exit your editor.

  4. Give the file the correct permissions by running sudo chmod a+x /usr/local/bin/xcodebuild

  5. You’re done! Re-run he command that caused the error.

You can also symlink /usr/local/bin/xcodebuild to /usr/bin/true

# Fix XcodeBuild Issue
if [[ -d '/Applications/XCode.app' ]] || [[ -d '/Developer/Applications/XCode.app' ]]; then
  echo 'Xcode Seems to be installed...'
else
  if [[ ! $(xcodebuild | grep 'requires Xcode') ]]; then
    echo 'Fixing the Xcodebuild issue by symlinking xcodebuild to true'
    ln -s /usr/bin/true /usr/local/bin/xcodebuild
    source '/etc/profile'
  fi
fi

Problem still exists in Yosemite. Wish there was a way NOT to install 3GB xcode 👎

Many of the patches to gyp mentioned above didn’t work for me. I managed to get this to work. In case any of you are still having problems, here’s what I did:

I noticed that the source code for gyp is trying to run xcodebuild, but if xcodebuild fails, then gyp fails. However, there is error handling in gyp in case xcodebuild runs successfully, but returns something other than expected. Relying on the behavior of gyp as described, I created an executable file called xcodebuild and put it in my search path. Here are its contents:

#!/bin/bash

exit 0

That’s it. All I wanted to do was make sure that gyp doesn’t freak out when it tries to run xcodebuild. I did not touch xcode-select or the gyp source.

ln -s /usr/bin/true /usr/local/bin/xcodebuild hint by @bdwyertech works perfectly, although I’m still not sure whether it has any unwanted side effects.

Not 3GB. Fully installed Xcode is 6GB according to AppCleaner, probably including libraries and frameworks outside Xcode. Utterly ridiculous that I have to give up 6GB on my 100GB SSD for something I’ll never use.

In case anyone is using Brew, it puts npm with node-gyp in the cellar:

/usr/local/Cellar/node/0.10.24/lib/node_modules/npm/bin/node-gyp-bin/node-gyp /usr/local/bin/node-gyp

Replace the first with a symlink to the second, and it works.

Hopefully the next node build is going to include this fix, otherwise I have to do this again on every release.

@TooTallNate I ran into this issue just now install node-expat. As suggested by you I patched

/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py

I only did this though;

def _GetSdkVersionInfoItem(self, sdk, infoitem):                                                                                                                                                                                                                                         
    try:                                                                                                                                                                                                                                                                        
        return self._GetStdout(['xcodebuild', '-version', '-sdk', sdk, infoitem])                                                                                                                                                                                               
    except:                                                                                                                                                                                                                                                                     
        pass                                                                                                                                                                                                                                                                    
    return ""

This worked