Hey @pyramation @benasher44, hope you're well!
The node-addon-api@^1.6.3 dependency is pretty ancient by now:
https://github.com/launchql/libpg-query-node/blob/badd4c85da02e8a7badfb050632e7d8010e8ec73/package.json#L30-L34
The current version is node-addon-api@8.0.0 (released 5 Mar 2024)
The old version of node-addon-api can cause weird conflicts - eg. running pnpm install on a project that has both libpg-query and sharp leads to this confusing error (../common.cc:12:10: fatal error: 'napi.h' file not found) in the sharp build:
➜ preflight-test-project-next-js-passing git:(main) ✗ pnpm i
Packages: +638
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Progress: resolved 707, reused 622, downloaded 17, added 638, done
node_modules/.pnpm/sharp@0.33.3/node_modules/sharp: Running install script, failed in 4.6s
.../sharp@0.33.3/node_modules/sharp install$ node install/check
│ sharp: Detected globally-installed libvips v8.15.2
│ sharp: Attempting to build from source via node-gyp
│ sharp: Found node-addon-api
│ sharp: Found node-gyp version 10.1.0
│ sharp: See https://sharp.pixelplumbing.com/install#building-from-source
│ gyp info it worked if it ends with ok
│ gyp info using node-gyp@10.0.1
│ gyp info using node@20.12.0 | darwin | arm64
│ gyp info chdir src
│ gyp info find Python using Python version 3.12.2 found at "/opt/homebrew/opt/python@3.12/bin/python3.12"
│ gyp info spawn /opt/homebrew/opt/python@3.12/bin/python3.12
│ gyp info spawn args [
│ gyp info spawn args '/Users/k/.cache/node/corepack/v1/pnpm/9.0.0-beta.1/dist/node_modules/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 '/Users/k/p/preflight-test-project-next-js-passing/node_modules/.pnpm/sharp@0.33.3/node_modules/sharp/src/build/config.gypi',
│ gyp info spawn args '-I',
│ gyp info spawn args '/Users/k/.cache/node/corepack/v1/pnpm/9.0.0-beta.1/dist/node_modules/node-gyp/addon.gypi',
│ gyp info spawn args '-I',
│ gyp info spawn args '/Users/k/Library/Caches/node-gyp/20.12.0/include/node/common.gypi',
│ gyp info spawn args '-Dlibrary=shared_library',
│ gyp info spawn args '-Dvisibility=default',
│ gyp info spawn args '-Dnode_root_dir=/Users/k/Library/Caches/node-gyp/20.12.0',
│ gyp info spawn args '-Dnode_gyp_dir=/Users/k/.cache/node/corepack/v1/pnpm/9.0.0-beta.1/dist/node_modules/node-gyp',
│ gyp info spawn args '-Dnode_lib_file=/Users/k/Library/Caches/node-gyp/20.12.0/<(target_arch)/node.lib',
│ gyp info spawn args '-Dmodule_root_dir=/Users/k/p/preflight-test-project-next-js-passing/node_modules/.pnpm/sharp@0.33.3/node_modules/sharp/src',
│ 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 args ]
│ <string>:114: SyntaxWarning: invalid escape sequence '\/'
│ gyp info spawn make
│ gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
│ CC(target) Release/obj.target/nothing/../../../../node-addon-api@1.7.2/node_modules/node-addon-api/src/nothing.o
│ LIBTOOL-STATIC Release/nothing.a
│ warning: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: archive library: Release/nothing.a the table of contents is empty (no object file members in t…
│ TOUCH Release/obj.target/libvips-cpp.stamp
│ CXX(target) Release/obj.target/sharp-darwin-arm64/common.o
│ ../common.cc:12:10: fatal error: 'napi.h' file not found
│ #include <napi.h>
│ ^~~~~~~~
│ 1 error generated.
│ make: *** [Release/obj.target/sharp-darwin-arm64/common.o] Error 1
│ gyp ERR! build error
│ gyp ERR! stack Error: `make` failed with exit code: 2
│ gyp ERR! stack at ChildProcess.<anonymous> (/Users/k/.cache/node/corepack/v1/pnpm/9.0.0-beta.1/dist/node_modules/node-gyp/lib/build.js:209:23)
│ gyp ERR! System Darwin 23.4.0
│ gyp ERR! command "/opt/homebrew/Cellar/node@20/20.12.0/bin/node" "/Users/k/.cache/node/corepack/v1/pnpm/9.0.0-beta.1/dist/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--directory=src"
│ gyp ERR! cwd /Users/k/p/preflight-test-project-next-js-passing/node_modules/.pnpm/sharp@0.33.3/node_modules/sharp/src
│ gyp ERR! node -v v20.12.0
│ gyp ERR! node-gyp -v v10.0.1
│ gyp ERR! not ok
└─ Failed in 4.6s at /Users/k/p/preflight-test-project-next-js-passing/node_modules/.pnpm/sharp@0.33.3/node_modules/sharp
node_modules/.pnpm/libpg-query@16.1.0_encoding@0.1.13/node_modules/libpg-query: Running install script...
ELIFECYCLE Command failed with exit code 1.
Removing libpg-query and running pnpm install resolves the issue with building sharp.
History
node-addon-api was introduced in a commit by @ethanresnick in July 2019:
Hey @pyramation @benasher44, hope you're well!
The
node-addon-api@^1.6.3dependency is pretty ancient by now:https://github.com/launchql/libpg-query-node/blob/badd4c85da02e8a7badfb050632e7d8010e8ec73/package.json#L30-L34
The current version is
node-addon-api@8.0.0(released 5 Mar 2024)The old version of
node-addon-apican cause weird conflicts - eg. runningpnpm installon a project that has bothlibpg-queryandsharpleads to this confusing error (../common.cc:12:10: fatal error: 'napi.h' file not found) in thesharpbuild:Removing
libpg-queryand runningpnpm installresolves the issue with buildingsharp.History
node-addon-apiwas introduced in a commit by @ethanresnick in July 2019: