Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node-gyp rebuild failed on MacOS #1464

Closed
realdennis opened this issue Jun 11, 2018 · 38 comments
Closed

node-gyp rebuild failed on MacOS #1464

realdennis opened this issue Jun 11, 2018 · 38 comments

Comments

@realdennis
Copy link

  • 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

@bnoordhuis
Copy link
Member

You can ignore that xcode-select error; if you upgrade node-gyp, you won't even see it. What's the actual build error?

@realdennis
Copy link
Author

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'

@richardlau
Copy link
Member

This is #1454 fixed by #1455.

@bnoordhuis
Copy link
Member

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.

@agm1984
Copy link

agm1984 commented Oct 12, 2018

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.

@aguynamedben
Copy link

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

@csergiu
Copy link

csergiu commented Oct 31, 2018

@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.

@aguynamedben
Copy link

@csergiu Can't figure it out. Have been trying various things for 1.5 days now.

@richardlau @bnoordhuis Any ideas? Should this be reopened?

@aguynamedben
Copy link

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.

@richardlau
Copy link
Member

What is the output of xcodebuild -version?

@csergiu
Copy link

csergiu commented Oct 31, 2018

@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.

@spjsschl
Copy link

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

@spjsschl
Copy link

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

@richardlau
Copy link
Member

Maybe refack/GYP3#1 would address this, or at least provide a more meaningful error message.

@allanberrocal
Copy link

allanberrocal commented Nov 3, 2018

@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)

@aguynamedben
Copy link

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

@DaveChambers
Copy link

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

@njbarrett
Copy link

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

@christopher-francisco
Copy link

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

@teddis
Copy link

teddis commented Dec 29, 2018

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.

> cld@2.4.8 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 typegoose@5.4.1 requires a peer of mongoose@5.0.0 but none is installed. You must install peer dependencies yourself.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! cld@2.4.8 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the cld@2.4.8 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

@alexanmtz
Copy link

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

@ahmadferdous
Copy link

@allanberrocal Your suggestion solved the issue. Thanks!

@superman285
Copy link

I face the same problem ,I got crazy.. I am trying the ways you suggest

@reneweteling
Copy link

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

@alun
Copy link

alun commented Feb 28, 2019

#1464 (comment)

  • removed node_modules
  • removed node-gyp object from package-lock.json as well
    after above npm install finished fine

@Vipinunnikrishnan
Copy link

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

This helped to fix the issue

@germanenik
Copy link

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?

@AdamBD
Copy link

AdamBD commented Apr 21, 2019

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

@eswardhinak
Copy link

@alexanmtz that link solved it for me! Thanks :)

@Muzzera
Copy link

Muzzera commented Aug 20, 2019

changed my node-sass for the last version and Voi la

@w3debugger
Copy link

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

@cclauss
Copy link
Contributor

cclauss commented Oct 30, 2019

For those upgrading to macOS Catalina, please checkout #1940

breville added a commit to code-dot-org/code-dot-org that referenced this issue Nov 3, 2019
This upgrades node-sass.

node-sass uses node-gyp, and the version we were using had a problem with recognising some versions of the xcode command-line tools.  See nodejs/node-gyp#1464.  Ugrading node-sass has pulled in a newer version of node-gyp and now it works again.
@bvenkatr
Copy link

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

@pedro-machado-tala
Copy link

pedro-machado-tala commented Dec 21, 2019

This works for me

npm install -g n
n 8.8.1

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

@bmfay
Copy link

bmfay commented Apr 8, 2020

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.

@segabor
Copy link

segabor commented Apr 28, 2020

@bmfay your solution worked out. Saved my day, thanks!

@rahianeja
Copy link

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

@mboutin-qohash
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests