node-gyp: node-gyp rebuild failed on MacOS

  • Node Version: node v10.4.0 npm 6.1.0
  • Platform: MacOS
  • Compiler: Apple LLVM version 10.0.0 (clang-1000.10.25.5)
  • Module:
Verbose output (from npm or node-gyp):
> node-gyp rebuild

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

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

Some strange behavior: When I use the npm script to run the node-gyp would rebuild failed, but ./node_modules/node-gyp/bin/node-gyp.js will run ok.

$ xcode-select -p /Library/Developer/CommandLineTools

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 8
  • Comments: 38 (6 by maintainers)

Commits related to this issue

Most upvoted comments

@spjsschl

I fixed the $ xcodebuild -version error doing the following:

  1. Go to Xcode>Preferences>Locations
  2. Make a selection in Command Line Tools For me it was Xcode 10.1

I’m troubleshooting another problem with npm install Hope that works

UPDATE: I got away with the npm install error described by @aguynamedben by switching the active environment to one running python 2.7 (I got the error while the active env had python 3.6)

This was the only way I was able to solve this. manually setting this in Xcode settings:

Screen Shot 2019-04-21 at 5 21 39 PM

deleting my lock file, node_modules folder then reinstalling with npm install resolved my issue

I’m seeing this with:

  • node-gyp 3.8.0
  • Node 10.2.0

I don’t have XCode installed, but I do have the Command Line Tools installed. It seems like node-gyp is having an issue determining something about the XCode environment (xcode_emulation.py).

I’m installing XCode and will try after that.

Any ideas?

binding.gyp: https://gist.github.com/aguynamedben/f46b059e5551afebd964da130614d78c

Command that is failing:

$ LDFLAGS='/usr/local/opt/openssl/lib/libcrypto.a' npm rebuild sqlite3 --build-from-source --sqlite_libname=sqlcipher --sqlite=`brew --prefix` --runtime=electron --target=3.0.6 --dist-url=https://atom.io/download/electron

Error:

  File "/Users/ben/.nvm/versions/node/v10.2.0/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py", line 551, in GetCflags
    archs = self.GetActiveArchs(self.configname)
  File "/Users/ben/.nvm/versions/node/v10.2.0/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py", line 420, in GetActiveArchs
    xcode_archs_default = GetXcodeArchsDefault()
  File "/Users/ben/.nvm/versions/node/v10.2.0/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py", line 118, in GetXcodeArchsDefault
    xcode_version, _ = XcodeVersion()
  File "/Users/ben/.nvm/versions/node/v10.2.0/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py", line 1265, in XcodeVersion
    version = re.match(r'(\d\.\d\.?\d*)', version).groups()[0]
AttributeError: 'NoneType' object has no attribute 'groups'
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (/Users/ben/.nvm/versions/node/v10.2.0/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:336:16)
gyp ERR! stack     at ChildProcess.emit (events.js:182:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:237:12)
gyp ERR! System Darwin 17.7.0
gyp ERR! command "/Users/ben/.nvm/versions/node/v10.2.0/bin/node" "/Users/ben/.nvm/versions/node/v10.2.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "--fallback-to-build" "--module=/Users/ben/code/tesla/node_modules/sqlite3/lib/binding/electron-v3.0-darwin-x64/node_sqlite3.node" "--module_name=node_sqlite3" "--module_path=/Users/ben/code/tesla/node_modules/sqlite3/lib/binding/electron-v3.0-darwin-x64" "--napi_version=3" "--node_abi_napi=napi" "--dist-url=https://atom.io/download/electron"
gyp ERR! cwd /Users/ben/code/tesla/node_modules/sqlite3
gyp ERR! node -v v10.2.0
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
node-pre-gyp ERR! build error
node-pre-gyp ERR! stack Error: Failed to execute '/Users/ben/.nvm/versions/node/v10.2.0/bin/node /Users/ben/.nvm/versions/node/v10.2.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/Users/ben/code/tesla/node_modules/sqlite3/lib/binding/electron-v3.0-darwin-x64/node_sqlite3.node --module_name=node_sqlite3 --module_path=/Users/ben/code/tesla/node_modules/sqlite3/lib/binding/electron-v3.0-darwin-x64 --napi_version=3 --node_abi_napi=napi --dist-url=https://atom.io/download/electron' (1)
node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (/Users/ben/code/tesla/node_modules/node-pre-gyp/lib/util/compile.js:83:29)
node-pre-gyp ERR! stack     at ChildProcess.emit (events.js:182:13)
node-pre-gyp ERR! stack     at maybeClose (internal/child_process.js:961:16)
node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:248:5)
node-pre-gyp ERR! System Darwin 17.7.0
node-pre-gyp ERR! command "/Users/ben/.nvm/versions/node/v10.2.0/bin/node" "/Users/ben/code/tesla/node_modules/sqlite3/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd /Users/ben/code/tesla/node_modules/sqlite3
node-pre-gyp ERR! node -v v10.2.0
node-pre-gyp ERR! node-pre-gyp -v v0.10.3
node-pre-gyp ERR! not ok
Failed to execute '/Users/ben/.nvm/versions/node/v10.2.0/bin/node /Users/ben/.nvm/versions/node/v10.2.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/Users/ben/code/tesla/node_modules/sqlite3/lib/binding/electron-v3.0-darwin-x64/node_sqlite3.node --module_name=node_sqlite3 --module_path=/Users/ben/code/tesla/node_modules/sqlite3/lib/binding/electron-v3.0-darwin-x64 --napi_version=3 --node_abi_napi=napi --dist-url=https://atom.io/download/electron' (1)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! sqlite3@4.0.2 install: `node-pre-gyp install --fallback-to-build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the sqlite3@4.0.2 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/ben/.npm/_logs/2018-10-30T15_21_06_129Z-debug.log

macOS version: High Sierra, 10.13.6

$ node --version
v10.2.0

$ yarn list --pattern "node-gyp" --depth=0
yarn list v1.10.1
└─ node-gyp@3.8.0

$ yarn list --pattern "node-abi" --depth=0
yarn list v1.10.1
└─ node-abi@2.4.5

$ gcc --version
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 10.0.0 (clang-1000.10.44.2)
Target: x86_64-apple-darwin17.7.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

I just had this problem. After some diagnosis, I was able to just update the version for node-gyp inside the package-lock.json.

I’ve never had to edit the file directly before, but mine was throwing the exact same error as the one posted here by realdennis.

Mine was node-sassfailing and it was depending on node-gyp v3.3.

Here is the code inside my package-lock.json for reference and context:

        "node-sass": {
            "version": "4.7.2",
            "resolved": "https://registry.npmjs.org/node-sass/-/node-sass-4.7.2.tgz",
            "integrity": "sha512-CaV+wLqZ7//Jdom5aUFCpGNoECd7BbNhjuwdsX/LkXBrHl8eb1Wjw4HvWqcFvhr5KuNgAk8i/myf/MQ1YYeroA==",
            "dev": true,
            "requires": {
                "async-foreach": "^0.1.3",
                "chalk": "^1.1.1",
                "cross-spawn": "^3.0.0",
                "gaze": "^1.0.0",
                "get-stdin": "^4.0.1",
                "glob": "^7.0.3",
                "in-publish": "^2.0.0",
                "lodash.assign": "^4.2.0",
                "lodash.clonedeep": "^4.3.2",
                "lodash.mergewith": "^4.6.0",
                "meow": "^3.7.0",
                "mkdirp": "^0.5.1",
                "nan": "^2.3.2",
                "node-gyp": "^3.7.0",
                "npmlog": "^4.0.0",
                "request": "~2.79.0",
                "sass-graph": "^2.2.4",
                "stdout-stream": "^1.4.0",
                "true-case-path": "^1.0.2"
            },

I simply changed it from 3.3 to 3.7 and my npm install was able to complete successfully.

In case it helps anybody, for me downgrading node (installed with brew) to LTS (v10.13.0) worked.

Running sudo xcode-select --switch /Library/Developer/CommandLineTools fixed it for me

After trying most of the above, what ended up working for me was, believe it or not, simply updating node to the latest version.

sudo npm cache clean -f
sudo npm install -g n
sudo n stable

Depending on the dependencies of your particular project, you may not be able to use the latest stable version of node, but you can try upgrading to the latest version your project allows and see if it resolves the issue as it did for me.

I faced this when I updated my macOS to Catalina. It is fixed 🎉

  1. Installed xcode builds
  2. removed yarn.lock / package-lock.json files
  3. run yarn

Yep, if you upgrade to 3.6.3 or 3.7.0 things should work. I’ll go ahead and close this out but let me know if you still have issues after upgrading.

For those upgrading to macOS Catalina, please checkout #1940

I’ve tried several solutions and this one seems working: https://blog.greggant.com/posts/2018/01/10/node-sass-fails-installing.html

After trying most of the above, what ended up working for me was, believe it or not, simply updating node to the latest version.

sudo npm cache clean -f
sudo npm install -g n
sudo n stable

Depending on the dependencies of your particular project, you may not be able to use the latest stable version of node, but you can try upgrading to the latest version your project allows and see if it resolves the issue as it did for me.

This worked for me

xcode_emulation.py in XcodeVersion version = re.match(r'(\d\.\d\.?\d*)', version).groups()[0] AttributeError: ‘NoneType’ object has no attribute ‘groups’

Verbose output
Traceback (most recent call last):
  File "/Users/dennis/.nvm/versions/node/v10.3.0/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py", line 16, in <module>
    sys.exit(gyp.script_main())
  File "/Users/dennis/.nvm/versions/node/v10.3.0/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 545, in script_main
    return main(sys.argv[1:])
  File "/Users/dennis/.nvm/versions/node/v10.3.0/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 538, in main
    return gyp_main(args)
  File "/Users/dennis/.nvm/versions/node/v10.3.0/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 523, in gyp_main
    generator.GenerateOutput(flat_list, targets, data, params)
  File "/Users/dennis/.nvm/versions/node/v10.3.0/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py", line 2170, in GenerateOutput
    part_of_all=qualified_target in needed_targets)
  File "/Users/dennis/.nvm/versions/node/v10.3.0/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py", line 795, in Write
    self.Pchify))
  File "/Users/dennis/.nvm/versions/node/v10.3.0/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py", line 1190, in WriteSources
    cflags = self.xcode_settings.GetCflags(configname)
  File "/Users/dennis/.nvm/versions/node/v10.3.0/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py", line 551, in GetCflags
    archs = self.GetActiveArchs(self.configname)
  File "/Users/dennis/.nvm/versions/node/v10.3.0/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py", line 420, in GetActiveArchs
    xcode_archs_default = GetXcodeArchsDefault()
  File "/Users/dennis/.nvm/versions/node/v10.3.0/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py", line 118, in GetXcodeArchsDefault
    xcode_version, _ = XcodeVersion()
  File "/Users/dennis/.nvm/versions/node/v10.3.0/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py", line 1265, in XcodeVersion
    version = re.match(r'(\d\.\d\.?\d*)', version).groups()[0]
AttributeError: 'NoneType' object has no attribute 'groups'

This works for me

npm install -g n n 8.8.1

sudo npm explore npm -g – npm install node-gyp@latest

Downgrading from Python3.xx to Python2.xx fixed the issue

Running sudo xcode-select --switch /Library/Developer/CommandLineTools fixed it for me

This helped to fix the issue

ok, so for me the following worked, when running Xcode version i got this

z-app git:(master) ✗ xcodebuild -version
xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance

This usually happens when MacOs has an update to Xcode, just open Xcode and see if you need to install some additional stuff, after doing this I was golden.

image

It looks like yesterday Apple released some updates to High Sierra and Command Line Tools… going to try them now and post back if it’s still happening.

image

Yesterday I was also trying with only Command Line Tools installed, now I’ve installed full XCode, so that will also be impacting my 2nd attempt.

@aguynamedben

I’m having the same issue with macOS version: High Sierra, 10.13.6, Node v11.0.0 when running npm rebuild node-sass. Let me know if you’ve managed to fix it somehow.

@Vipinunnikrishnan after 2h searching for answers, yours worked for me! Ty

@alexanmtz that link solved it for me! Thanks 😃

The same issue as @teddis except I have node-pre-gyp instead of node-gyp. I was just trying to run an open source project, didn’t know it would turn into this. Any ideas?

Following up… some combination of installing full XCode and updating my Command Line Tools fixed this for me.

Maybe https://github.com/refack/GYP/pull/1 would address this, or at least provide a more meaningful error message.