Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Unable to build: napi.h not found #338

Closed
fxha opened this issue Dec 2, 2020 · 4 comments
Closed

Unable to build: napi.h not found #338

fxha opened this issue Dec 2, 2020 · 4 comments

Comments

@fxha
Copy link

fxha commented Dec 2, 2020

Prerequisites

  • keytar v7.2.0
  • Node v14.14.0
  • Linux, g++ v10.2.1 (not tested on other OSs)
  • Build against Electron 11.0.3

Description

We are unable to build keytar v7.2.0 due to #325. The only way to build keytar is adding "<!@(node -p \"require('node-addon-api').include\")" to binding.gyp but include is marked as deprecate.

Additional Information

Building module: keytar, Completed: 5gyp info find Python using Python version 3.9.0 found at "/usr/bin/python3"
gyp info spawn /usr/bin/python3
gyp info spawn args [
gyp info spawn args   '/some_path/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   '/some_path/node_modules/keytar/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/some_path/node_modules/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/some_path/node_modules/keytar/11.0.3/include/node/common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=/some_path/node_modules/keytar/11.0.3',
gyp info spawn args   '-Dnode_gyp_dir=/some_path/node_modules/node-gyp',
gyp info spawn args   '-Dnode_lib_file=/some_path/node_modules/keytar/11.0.3/<(target_arch)/node.lib',
gyp info spawn args   '-Dmodule_root_dir=/some_path/node_modules/keytar',
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 ]
Building module: keytar, Completed: 5gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
Building module: keytar, Completed: 5make: Verzeichnis „/some_path/node_modules/keytar/build“ wird betreten
  CXX(target) Release/obj.target/keytar/src/async.o
Building module: keytar, Completed: 5../src/async.cc:4:10: schwerwiegender Fehler: napi.h: Datei oder Verzeichnis nicht gefunden
    4 | #include "napi.h"
      |          ^~~~~~~~
Kompilierung beendet.
make: *** [keytar.target.mk:121: Release/obj.target/keytar/src/async.o] Fehler 1
make: Verzeichnis „/some_path/node_modules/keytar/build“ wird verlassen
Rebuild Failed

An unhandled error occurred inside electron-rebuild
node-gyp failed to rebuild '/some_path/node_modules/keytar'.
Error: `make` failed with exit code: 2



Error: node-gyp failed to rebuild '/some_path/node_modules/keytar'.
Error: `make` failed with exit code: 2


    at ModuleRebuilder.rebuildNodeGypModule (/some_path/node_modules/electron-rebuild/lib/src/module-rebuilder.js:193:19)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async Rebuilder.rebuildModuleAt (/some_path/node_modules/electron-rebuild/lib/src/rebuild.js:183:9)
    at async Rebuilder.rebuild (/some_path/node_modules/electron-rebuild/lib/src/rebuild.js:145:17)
    at async /some_path/node_modules/electron-rebuild/lib/src/cli.js:145:9
error Command failed with exit code 255
@fxha fxha closed this as completed Dec 2, 2020
@shiftkey
Copy link
Contributor

shiftkey commented Dec 2, 2020

@fxha did this get resolved?

@fxha
Copy link
Author

fxha commented Dec 2, 2020

@shiftkey Sorry that I just closed the issue. We upgraded from v6.x and noticed later that keytar used node-addon-api v3.0.0 instead the latest version 3.0.2. It seems that NAPI was wrongly resolved because after removing the outdated entry from our yarn.lock, everything works fine. It would be a good idea to explicitly use v3.0.2 to prevent this issue. It's unknown to me, why yarn resolved this to a bugged version instead to the latest stable minor.

@shiftkey
Copy link
Contributor

shiftkey commented Dec 2, 2020

It would be a good idea to explicitly use v3.0.2 to prevent this issue.

We're resolving to v3.0.2 in our lockfile but I'd take a PR to bump package.json explicitly to the latest version. I haven't spotted the issue personally and the changelogs for node-addon-api don't make it clear what upstream issue this behaviour could be, so any extra information you have would be greatly appreciated.

@fxha
Copy link
Author

fxha commented Dec 2, 2020

I haven't spotted the issue personally and the changelogs for node-addon-api don't make it clear what upstream issue this behaviour could be, so any extra information you have would be greatly appreciated.

I noticed that running node -p "require('node-addon-api').include_dir" returned undefined but include the correct path. Later, I spotted that include_dir is only available since v3.0.2, see index.js (v3.0.1) or changelog. Forcefully upgrading all node-addon-api packages resolved the issue.

2020-09-18 Version 3.0.2,
[...]
Introduced include_dir for use with gyp in a scalar context.

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

No branches or pull requests

2 participants