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
You can ignore that xcode-select error; if you upgrade node-gyp, you won't even see it. What's the actual build error?
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 is https://github.com/nodejs/node-gyp/issues/1454 fixed by https://github.com/nodejs/node-gyp/pull/1455.
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.
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.
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! [email protected] install: `node-pre-gyp install --fallback-to-build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] 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
└─ [email protected]
$ yarn list --pattern "node-abi" --depth=0
yarn list v1.10.1
└─ [email protected]
$ 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
@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.
@csergiu Can't figure it out. Have been trying various things for 1.5 days now.
@richardlau @bnoordhuis Any ideas? Should this be reopened?
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.

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.
What is the output of xcodebuild -version?
@aguynamedben are you running it from an IDE terminal by any chance? it seems to work for me now if I run it from iTerm, not sure what bins RubyMine was using.
What is the output of
xcodebuild -version? For me it is:
$ xcodebuild -version
xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance
Running sudo xcode-select --switch /Library/Developer/CommandLineTools fixed it for me
Maybe https://github.com/refack/GYP/pull/1 would address this, or at least provide a more meaningful error message.
@spjsschl
I fixed the $ xcodebuild -version error doing the following:
- Go to Xcode>Preferences>Locations
- 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)
Following up... some combination of installing full XCode and updating my Command Line Tools fixed this for me.
In case it helps anybody, for me downgrading node (installed with brew) to LTS (v10.13.0) worked.
deleting my lock file, node_modules folder then reinstalling with npm install resolved my issue
I'll just install xcode. Not keeping track of every sudo you run feels like you lose track of the changes you've done to your laptop to get to the point where it currently is
I was hopeful one of the above solutions might work, but I'm still unable to get past this. My config: node 10.12.0, npm 6.5.0, node-gyp 3.8.0, Mac Mojave 10.14.2, Xcode 10.1 (and installed its components). I removed node-modules/ and package-lock.json before restarting npm install.
> [email protected] install /Users/cheech/src/orderscape/node_modules/cld
> node-gyp rebuild
CXX(target) Release/obj.target/cld-c/deps/cld/internal/cldutil.o
CXX(target) Release/obj.target/cld-c/deps/cld/internal/cldutil_shared.o
CXX(target) Release/obj.target/cld-c/deps/cld/internal/compact_lang_det.o
CXX(target) Release/obj.target/cld-c/deps/cld/internal/compact_lang_det_hint_code.o
CXX(target) Release/obj.target/cld-c/deps/cld/internal/compact_lang_det_impl.o
CXX(target) Release/obj.target/cld-c/deps/cld/internal/debug.o
CXX(target) Release/obj.target/cld-c/deps/cld/internal/fixunicodevalue.o
CXX(target) Release/obj.target/cld-c/deps/cld/internal/generated_entities.o
CXX(target) Release/obj.target/cld-c/deps/cld/internal/generated_language.o
CXX(target) Release/obj.target/cld-c/deps/cld/internal/generated_ulscript.o
CXX(target) Release/obj.target/cld-c/deps/cld/internal/getonescriptspan.o
CXX(target) Release/obj.target/cld-c/deps/cld/internal/lang_script.o
CXX(target) Release/obj.target/cld-c/deps/cld/internal/offsetmap.o
CXX(target) Release/obj.target/cld-c/deps/cld/internal/scoreonescriptspan.o
CXX(target) Release/obj.target/cld-c/deps/cld/internal/tote.o
CXX(target) Release/obj.target/cld-c/deps/cld/internal/utf8statetable.o
CXX(target) Release/obj.target/cld-c/deps/cld/internal/cld_generated_cjk_uni_prop_80.o
CXX(target) Release/obj.target/cld-c/deps/cld/internal/cld2_generated_cjk_compatible.o
CXX(target) Release/obj.target/cld-c/deps/cld/internal/cld_generated_cjk_delta_bi_32.o
CXX(target) Release/obj.target/cld-c/deps/cld/internal/generated_distinct_bi_0.o
CXX(target) Release/obj.target/cld-c/deps/cld/internal/cld2_generated_quad0122.o
CXX(target) Release/obj.target/cld-c/deps/cld/internal/cld2_generated_deltaocta0122.o
CXX(target) Release/obj.target/cld-c/deps/cld/internal/cld2_generated_deltaoctachrome.o
CXX(target) Release/obj.target/cld-c/deps/cld/internal/cld2_generated_distinctocta0122.o
CXX(target) Release/obj.target/cld-c/deps/cld/internal/cld2_generated_distinctoctachrome.o
CXX(target) Release/obj.target/cld-c/deps/cld/internal/cld2_generated_quadchrome_16.o
CXX(target) Release/obj.target/cld-c/deps/cld/internal/cld2_generated_quadchrome_2.o
CXX(target) Release/obj.target/cld-c/deps/cld/internal/cld_generated_score_quad_octa_0122.o
CXX(target) Release/obj.target/cld-c/deps/cld/internal/cld_generated_score_quad_octa_2.o
LIBTOOL-STATIC Release/cld-c.a
libtool: unrecognized option `-static'
libtool: Try `libtool --help' for more information.
make: *** [Release/cld-c.a] Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:262:23)
gyp ERR! stack at ChildProcess.emit (events.js:182:13)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:240:12)
gyp ERR! System Darwin 18.2.0
gyp ERR! command "/usr/local/Cellar/node/10.12.0/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/cheech/src/orderscape/node_modules/cld
gyp ERR! node -v v10.12.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
npm WARN [email protected] requires a peer of [email protected] but none is installed. You must install peer dependencies yourself.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] 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/cheech/.npm/_logs/2018-12-29T02_29_19_868Z-debug.log