Heroku node.h error during deploy, causing deploy to fail

Hi there!

Like the title suggests, for some reason I’m unable to deploy my application. To be clear, I have always been able to deploy using FlyCTL before and I’m running the newest version of FlyCTL, but for some reason I no longer can without getting what seem to be server-side errors :frowning: Here is the build log, including the path to a log file I can’t access:

==> Verifying app config
--> Verified app config
==> Building image
Remote builder fly-builder-frosty-waterfall-5197 ready
==> Building image with Buildpacks
--> docker host: 20.10.12 linux x86_64
20: Pulling from heroku/buildpacks
Digest: sha256:c0d7e5ab49c0fc4ca1e4a530ca7497ce805834f632fbd7564b21857707616963
Status: Image is up to date for heroku/buildpacks:20
20-cnb: Pulling from heroku/heroku
Digest: sha256:8ad29a253c1226810078c9a413665fb320c5703188dbe27c3cc520a08371eb81
Status: Image is up to date for heroku/heroku:20-cnb
===> DETECTING
heroku/nodejs-engine 0.8.12
heroku/nodejs-npm    0.5.2
heroku/procfile      2.0.0
===> ANALYZING
Previous image with name "registry.fly.io/projectname:cache" not found
===> RESTORING
===> BUILDING

[Heroku Node.js Engine Buildpack]

[Checking Node.js version]
Detected Node.js version range: *
Resolved Node.js version: 19.0.1

[Installing Node.js distribution]
Downloading Node.js 19.0.1
Extracting Node.js 19.0.1
Installing Node.js 19.0.1
[INFO] Installing toolbox
[INFO] - yj
[INFO] Using npm v8.19.2 from Node
[INFO] Installing node modules from ./package-lock.json
npm WARN config production Use `--omit=dev` instead.
npm notice
npm notice New major version of npm available! 8.19.2 -> 9.1.1
npm notice Changelog: <https://github.com/npm/cli/releases/tag/v9.1.1>
npm notice Run `npm install -g npm@9.1.1` to update!
npm notice
npm ERR! code 1
npm ERR! path /workspace/node_modules/better-sqlite3
npm ERR! command failed
npm ERR! command sh -c -- prebuild-install || npm run build-release
npm ERR! > better-sqlite3@7.6.2 build-release
npm ERR! > node-gyp rebuild --release
npm ERR!
npm ERR! make: Entering directory '/workspace/node_modules/better-sqlite3/build'
npm ERR!   TOUCH ba23eeee118cd63e16015df367567cb043fed872.intermediate
npm ERR!   ACTION deps_sqlite3_gyp_locate_sqlite3_target_copy_builtin_sqlite3 ba23eeee118cd63e16015df367567cb043fed872.intermediate
npm ERR!   TOUCH Release/obj.target/deps/locate_sqlite3.stamp
npm ERR!   CC(target) Release/obj.target/sqlite3/gen/sqlite3/sqlite3.o
npm ERR!   AR(target) Release/obj.target/deps/sqlite3.a
npm ERR!   COPY Release/sqlite3.a
npm ERR!   CXX(target) Release/obj.target/better_sqlite3/src/better_sqlite3.o
npm ERR! rm ba23eeee118cd63e16015df367567cb043fed872.intermediate
npm ERR! make: Leaving directory '/workspace/node_modules/better-sqlite3/build'
npm ERR! prebuild-install warn install No prebuilt binaries found (target=19.0.1 runtime=node arch=x64 libc= platform=linux)
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@9.1.0
npm ERR! gyp info using node@19.0.1 | linux | x64
npm ERR! gyp info find Python using Python version 3.8.10 found at "/usr/bin/python3"
npm ERR! gyp http GET https://nodejs.org/download/release/v19.0.1/node-v19.0.1-headers.tar.gz
npm ERR! gyp http 200 https://nodejs.org/download/release/v19.0.1/node-v19.0.1-headers.tar.gz
npm ERR! gyp http GET https://nodejs.org/download/release/v19.0.1/SHASUMS256.txt
npm ERR! gyp http 200 https://nodejs.org/download/release/v19.0.1/SHASUMS256.txt
npm ERR! gyp info spawn /usr/bin/python3
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args   '/layers/heroku_nodejs-engine/dist/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   '/workspace/node_modules/better-sqlite3/build/config.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/layers/heroku_nodejs-engine/dist/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/home/heroku/.cache/node-gyp/19.0.1/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=/home/heroku/.cache/node-gyp/19.0.1',
npm ERR! gyp info spawn args   '-Dnode_gyp_dir=/layers/heroku_nodejs-engine/dist/lib/node_modules/npm/node_modules/node-gyp',
npm ERR! gyp info spawn args   '-Dnode_lib_file=/home/heroku/.cache/node-gyp/19.0.1/<(target_arch)/node.lib',
npm ERR! gyp info spawn args   '-Dmodule_root_dir=/workspace/node_modules/better-sqlite3',
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! gyp info spawn make
npm ERR! gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
npm ERR! In file included from ./src/better_sqlite3.lzz:11,
npm ERR!                  from ../src/better_sqlite3.cpp:4:
npm ERR! /home/heroku/.cache/node-gyp/19.0.1/include/node/node.h:996:51: warning: cast between incompatible function types from 'void (*)(v8::Local<v8::Object>, v8::Local<v8::Value>, v8::Local<v8::Context>)' to 'node::addon_context_register_func' {aka 'void (*)(v8::Local<v8::Object>, v8::Local<v8::Value>, v8::Local<v8::Context>, void*)'} [-Wcast-function-type]
npm ERR!   996 |       (node::addon_context_register_func) (regfunc),                  \
npm ERR!       |                                                   ^
npm ERR! /home/heroku/.cache/node-gyp/19.0.1/include/node/node.h:1014:3: note: in expansion of macro 'NODE_MODULE_CONTEXT_AWARE_X'
npm ERR!  1014 |   NODE_MODULE_CONTEXT_AWARE_X(modname, regfunc, NULL, 0)
npm ERR!       |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~
npm ERR! /home/heroku/.cache/node-gyp/19.0.1/include/node/node.h:1045:3: note: in expansion of macro 'NODE_MODULE_CONTEXT_AWARE'
npm ERR!  1045 |   NODE_MODULE_CONTEXT_AWARE(NODE_GYP_MODULE_NAME,                     \
npm ERR!       |   ^~~~~~~~~~~~~~~~~~~~~~~~~
npm ERR! ./src/better_sqlite3.lzz:67:1: note: in expansion of macro 'NODE_MODULE_INIT'
npm ERR! ./src/util/macros.lzz: In function 'void SetPrototypeGetter(v8::Isolate*, v8::Local<v8::External>, v8::Local<v8::FunctionTemplate>, const char*, v8::AccessorGetterCallback)':
npm ERR! ./src/util/macros.lzz:157:21: error: 'v8::AccessorSignature' has not been declared
npm ERR! ./src/util/binder.lzz: In static member function 'static bool Binder::IsPlainObject(v8::Isolate*, v8::Local<v8::Object>)':
npm ERR! ./src/util/binder.lzz:37:51: error: 'class v8::Object' has no member named 'CreationContext'; did you mean 'GetCreationContext'?
npm ERR! ./src/util/data.lzz: In function 'v8::Local<v8::Value> Data::GetValueJS(v8::Isolate*, sqlite3_stmt*, int, bool)':
npm ERR! ./src/util/data.lzz:73:92: warning: this statement may fall through [-Wimplicit-fallthrough=]
npm ERR! ./src/util/data.lzz:73:197: note: here
npm ERR! ./src/util/data.lzz: In function 'v8::Local<v8::Value> Data::GetValueJS(v8::Isolate*, sqlite3_value*, bool)':
npm ERR! ./src/util/data.lzz:77:81: warning: this statement may fall through [-Wimplicit-fallthrough=]
npm ERR! ./src/util/data.lzz:77:175: note: here
npm ERR! make: *** [better_sqlite3.target.mk:125: Release/obj.target/better_sqlite3/src/better_sqlite3.o] Error 1
npm ERR! gyp ERR! build error
npm ERR! gyp ERR! stack Error: `make` failed with exit code: 2
npm ERR! gyp ERR! stack     at ChildProcess.onExit (/layers/heroku_nodejs-engine/dist/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:201:23)
npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:513:28)
npm ERR! gyp ERR! stack     at ChildProcess._handle.onexit (node:internal/child_process:293:12)
npm ERR! gyp ERR! System Linux 5.12.2
npm ERR! gyp ERR! command "/layers/heroku_nodejs-engine/dist/bin/node" "/layers/heroku_nodejs-engine/dist/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--release"
npm ERR! gyp ERR! cwd /workspace/node_modules/better-sqlite3
npm ERR! gyp ERR! node -v v19.0.1
npm ERR! gyp ERR! node-gyp -v v9.1.0
npm ERR! gyp ERR! not ok

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/heroku/.npm/_logs/2022-11-14T15_43_58_178Z-debug-0.log
ERROR: failed to build: exit status 1
Error failed to fetch an image or build from source: executing lifecycle: failed with status code: 51

The error appears to come from node.h in the Heroku engine buildpack, but I’m not sure what I can do about said error… I’ve already tried updating Node, trying it on my MacBook instead of Windows, removing and recreating package-lock.json, but I keep getting the same error, unfortunately.

Just wanted to leave a reply in case anybody else gets this problem, I’ve solved it!

Here’s what worked for me: defining a specific Node & NPM version in package.json

"engines": {
    "npm": ">=8.0.0 <9.0.0",
    "node": ">=16.0.0 <17.0.0"
}