node-gyp: node-gyp rebuild is failing

  • Node Version:Node: v10.19.0 and NPM: 6.14.5
  • Platform: Ubuntu 20.04
  • Module: vscode-sqlite3
Verbose output (from npm or node-gyp):
gyp info it worked if it ends with ok
gyp info using node-gyp@6.1.0
gyp info using node@10.19.0 | linux | x64
gyp info find Python using Python version 2.7.18 found at "/usr/bin/python2"
gyp info spawn /usr/bin/python2
gyp info spawn args [ '/usr/share/nodejs/node-gyp/gyp/gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'make',
gyp info spawn args   '-I',
gyp info spawn args   '/home/varun/Desktop/WorkSpace/vscode/node_modules/vscode-sqlite3/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/usr/share/nodejs/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/usr/include/nodejs/common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=/usr/include/nodejs',
gyp info spawn args   '-Dnode_gyp_dir=/usr/share/nodejs/node-gyp',
gyp info spawn args   '-Dnode_lib_file=/usr/include/nodejs/<(target_arch)/node.lib',
gyp info spawn args   '-Dmodule_root_dir=/home/varun/Desktop/WorkSpace/vscode/node_modules/vscode-sqlite3',
gyp info spawn args   '-Dnode_engine=v8',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'build',
gyp info spawn args   '-Goutput_dir=.' ]
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
make: Entering directory '/home/varun/Desktop/WorkSpace/vscode/node_modules/vscode-sqlite3/build'
  ACTION deps_sqlite3_gyp_action_before_build_target_unpack_sqlite_dep Release/obj/gen/sqlite-autoconf-3280000/sqlite3.c
/bin/sh: 1: python: not found
make: *** [deps/action_before_build.target.mk:13: Release/obj/gen/sqlite-autoconf-3280000/sqlite3.c] Error 127
make: Leaving directory '/home/varun/Desktop/WorkSpace/vscode/node_modules/vscode-sqlite3/build'
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/share/nodejs/node-gyp/lib/build.js:194:23)
gyp ERR! stack     at ChildProcess.emit (events.js:198:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:248:12)
gyp ERR! System Linux 5.4.0-33-generic
gyp ERR! command "/usr/bin/node" "/usr/bin/node-gyp" "configure" "build"
gyp ERR! cwd /home/varun/Desktop/WorkSpace/vscode/node_modules/vscode-sqlite3
gyp ERR! node -v v10.19.0
gyp ERR! node-gyp -v v6.1.0
gyp ERR! not ok

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 31 (16 by maintainers)

Most upvoted comments

Would it be possible to change node-gyp so that it doesn’t fail when there are multiple python versions installed? Or at least that it gives a reasonable error message?

I run into problems with this module every 6 months or so and it always is super frustrating and difficult to find a solution (or the problem, in the first place). And I never even used this module directly but it’s a dependency for every other module out there.

This works for me 😃

npm install -g node-gyp

export npm_config_node_gyp=/usr/local/lib/node_modules/node-gyp/bin/node-gyp.js

rm -rf node_modules(if already there)

npm install

Please try: NODE_GYP_FORCE_PYTHON=python3 <your command goes here>

I’m sorry to re-open this, I’ve tried all the methods listed here, but none resolve my issue.

system: Macbook I’m using node = v12.20.2 and npm = 7.19.1, I’m using nvm to manage two different node environments. I thought it was because of the higher version of node that’s causing it, so I downgraded to v12.20.2.

with all the approaches listed here, I’m still obtaining this:

$ npm install --save @tensorflow/tfjs-node@1.2.3                                                  
npm ERR! code 1
npm ERR! path /Users/steveoni/Documents/Building-Data-Driven-Applications-with-Danfo.js-/chapter11/node_modules/@tensorflow/tfjs-node
npm ERR! command failed
npm ERR! command sh -c node scripts/install.js
npm ERR! * Downloading libtensorflow
npm ERR! 
npm ERR! * Building TensorFlow Node.js bindings
npm ERR! /Users/steveoni/Documents/Building-Data-Driven-Applications-with-Danfo.js-/chapter11/node_modules/@tensorflow/tfjs-node/scripts/install.js:157
npm ERR!       throw new Error('node-gyp rebuild failed with: ' + err);
npm ERR!       ^
npm ERR! 
npm ERR! Error: node-gyp rebuild failed with: Error: Command failed: node-gyp rebuild
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@7.1.2
npm ERR! gyp info using node@12.20.2 | darwin | x64
npm ERR! gyp info find Python using Python version 3.8.5 found at "/Users/steveoni/anaconda3/bin/python3"
npm ERR! gyp info spawn /Users/steveoni/anaconda3/bin/python3
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args   '/Users/steveoni/.nvm/versions/node/v12.20.2/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
npm ERR! gyp info spawn args   'binding.gyp',
npm ERR! gyp info spawn args   '-f',
npm ERR! gyp info spawn args   'make',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/Users/steveoni/Documents/Building-Data-Driven-Applications-with-Danfo.js-/chapter11/node_modules/@tensorflow/tfjs-node/build/config.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/Users/steveoni/.nvm/versions/node/v12.20.2/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/Users/steveoni/Library/Caches/node-gyp/12.20.2/include/node/common.gypi',
npm ERR! gyp info spawn args   '-Dlibrary=shared_library',
npm ERR! gyp info spawn args   '-Dvisibility=default',
npm ERR! gyp info spawn args   '-Dnode_root_dir=/Users/steveoni/Library/Caches/node-gyp/12.20.2',
npm ERR! gyp info spawn args   '-Dnode_gyp_dir=/Users/steveoni/.nvm/versions/node/v12.20.2/lib/node_modules/npm/node_modules/node-gyp',
npm ERR! gyp info spawn args   '-Dnode_lib_file=/Users/steveoni/Library/Caches/node-gyp/12.20.2/<(target_arch)/node.lib',
npm ERR! gyp info spawn args   '-Dmodule_root_dir=/Users/steveoni/Documents/Building-Data-Driven-Applications-with-Danfo.js-/chapter11/node_modules/@tensorflow/tfjs-node',
npm ERR! gyp info spawn args   '-Dnode_engine=v8',
npm ERR! gyp info spawn args   '--depth=.',
npm ERR! gyp info spawn args   '--no-parallel',
npm ERR! gyp info spawn args   '--generator-output',
npm ERR! gyp info spawn args   'build',
npm ERR! gyp info spawn args   '-Goutput_dir=.'
npm ERR! gyp info spawn args ]
npm ERR! No receipt for 'com.apple.pkg.CLTools_Executables' found at '/'.
npm ERR! No receipt for 'com.apple.pkg.DeveloperToolsCLILeo' found at '/'.
npm ERR! No receipt for 'com.apple.pkg.DeveloperToolsCLI' found at '/'.
npm ERR! 
npm ERR! 
npm ERR! 
npm ERR! Traceback (most recent call last):
npm ERR!   File "/Users/steveoni/.nvm/versions/node/v12.20.2/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py", line 1500, in XcodeVersion
npm ERR!     version_list = GetStdoutQuiet(["xcodebuild", "-version"]).splitlines()
npm ERR!   File "/Users/steveoni/.nvm/versions/node/v12.20.2/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py", line 1563, in GetStdoutQuiet
npm ERR!     raise GypError("Error %d running %s" % (job.returncode, cmdlist[0]))
npm ERR! gyp.common.GypError: Error 1 running xcodebuild
npm ERR! 
npm ERR! During handling of the above exception, another exception occurred:
npm ERR! 
npm ERR! Traceback (most recent call last):
npm ERR!   File "/Users/steveoni/.nvm/versions/node/v12.20.2/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py", line 51, in <module>
npm ERR!     sys.exit(gyp.script_main())
npm ERR!   File "/Users/steveoni/.nvm/versions/node/v12.20.2/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 670, in script_main
npm ERR!     return main(sys.argv[1:])
npm ERR!   File "/Users/steveoni/.nvm/versions/node/v12.20.2/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 662, in main
npm ERR!     return gyp_main(args)
npm ERR!   File "/Users/steveoni/.nvm/versions/node/v12.20.2/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 647, in gyp_main
npm ERR!     generator.GenerateOutput(flat_list, targets, data, params)
npm ERR!   File "/Users/steveoni/.nvm/versions/node/v12.20.2/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py", line 2451, in GenerateOutput
npm ERR!     writer.Write(
npm ERR!   File "/Users/steveoni/.nvm/versions/node/v12.20.2/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py", line 831, in Write
npm ERR!     self.WriteSources(
npm ERR!   File "/Users/steveoni/.nvm/versions/node/v12.20.2/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py", line 1302, in WriteSources
npm ERR!     cflags = self.xcode_settings.GetCflags(
npm ERR!   File "/Users/steveoni/.nvm/versions/node/v12.20.2/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py", line 661, in GetCflags
npm ERR!     archs = self.GetActiveArchs(self.configname)
npm ERR!   File "/Users/steveoni/.nvm/versions/node/v12.20.2/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py", line 515, in GetActiveArchs
npm ERR!     xcode_archs_default = GetXcodeArchsDefault()
npm ERR!   File "/Users/steveoni/.nvm/versions/node/v12.20.2/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py", line 122, in GetXcodeArchsDefault
npm ERR!     xcode_version, _ = XcodeVersion()
npm ERR!   File "/Users/steveoni/.nvm/versions/node/v12.20.2/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py", line 1511, in XcodeVersion
npm ERR!     version = CLTVersion()  # macOS Catalina returns 11.0.0.0.1.1567737322
npm ERR!   File "/Users/steveoni/.nvm/versions/node/v12.20.2/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py", line 1549, in CLTVersion
npm ERR!     return re.search(regex, output).groupdict()["version"]
npm ERR! AttributeError: 'NoneType' object has no attribute 'groupdict'
npm ERR! gyp ERR! configure error 
npm ERR! gyp ERR! stack Error: `gyp` failed with exit code: 1
npm ERR! gyp ERR! stack     at ChildProcess.onCpExit (/Users/steveoni/.nvm/versions/node/v12.20.2/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:351:16)
npm ERR! gyp ERR! stack     at ChildProcess.emit (events.js:314:20)
npm ERR! gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:276:12)
npm ERR! gyp ERR! System Darwin 19.6.0
npm ERR! gyp ERR! command "/Users/steveoni/.nvm/versions/node/v12.20.2/bin/node" "/Users/steveoni/.nvm/versions/node/v12.20.2/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
npm ERR! gyp ERR! cwd /Users/steveoni/Documents/Building-Data-Driven-Applications-with-Danfo.js-/chapter11/node_modules/@tensorflow/tfjs-node
npm ERR! gyp ERR! node -v v12.20.2
npm ERR! gyp ERR! node-gyp -v v7.1.2
npm ERR! gyp ERR! not ok 
npm ERR! 
npm ERR!     at /Users/steveoni/Documents/Building-Data-Driven-Applications-with-Danfo.js-/chapter11/node_modules/@tensorflow/tfjs-node/scripts/install.js:157:13
npm ERR!     at ChildProcess.exithandler (child_process.js:315:5)
npm ERR!     at ChildProcess.emit (events.js:314:20)
npm ERR!     at maybeClose (internal/child_process.js:1022:16)
npm ERR!     at Socket.<anonymous> (internal/child_process.js:444:11)
npm ERR!     at Socket.emit (events.js:314:20)
npm ERR!     at Pipe.<anonymous> (net.js:675:12)

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/steveoni/.npm/_logs/2021-07-09T23_41_50_867Z-debug.log

Thank you @cclauss, that actually worked.

What I am getting at is that I always find it difficult to find the correct solution.

In the last few hours I had a variety of different error messages from node-gyp, by trying to install the pg-native module. The error messages were:

  • No module named ast
  • TypeError: write() argument must be str, not bytes while trying to load binding.gyp
  • gyp: Call to ‘/usr/bin/pg_config --libdir’ returned exit status 1 while in binding.gyp. while trying to load binding.gyp (this one actually originated from a different module)

Googeling these errors took some hours and a lot of retries until I reached at this thread and discovered that I need to set NODE_GYP_FORCE_PYTHON. Inbetween there was something about upgrading node-gyp as well but couldn’t find how to do it when it isn’t even mentioned in the package-lock.json and not installed as global module. And as mentioned, I have errors like these from node-gyp every half year or so and on different projects.

If the Python version issue is the source of a significant portion of build fails for people then it would be a huge help if this module could test for that and display a nice error message (instead of failing with one of the ones above) or even just set NODE_GYP_FORCE_PYTHON itself so it doesn’t even fail.