node-keytar icon indicating copy to clipboard operation
node-keytar copied to clipboard

Unable to compile for electron target: caused by recent node-addon-api 3.1.0 => 3.2.0 update

Open vladimiry opened this issue 3 years ago • 19 comments

Steps to Reproduce

HOME=~/.electron-gyp node-gyp rebuild --target=13.0.0-beta.27 --arch=x64 --dist-url=https://electronjs.org/headers

Gives:

  CXX(target) Release/obj.target/keytar/src/async.o
In file included from ../node_modules/node-addon-api/napi.h:2725,
                 from ../src/async.cc:4:
../node_modules/node-addon-api/napi-inl.h: In member function ‘bool Napi::Object::Freeze()’:
../node_modules/node-addon-api/napi-inl.h:1393:24: error: ‘napi_object_freeze’ was not declared in this scope; did you mean ‘napi_object_expected’?
 1393 |   napi_status status = napi_object_freeze(_env, _value);
      |                        ^~~~~~~~~~~~~~~~~~
      |                        napi_object_expected
../node_modules/node-addon-api/napi-inl.h: In member function ‘bool Napi::Object::Seal()’:
../node_modules/node-addon-api/napi-inl.h:1399:24: error: ‘napi_object_seal’ was not declared in this scope; did you mean ‘napi_object’?
 1399 |   napi_status status = napi_object_seal(_env, _value);
      |                        ^~~~~~~~~~~~~~~~
      |                        napi_object
make: *** [keytar.target.mk:121: Release/obj.target/keytar/src/async.o] Error 1

Works fine if I downgrade node-addon-api 3.2.0 => 3.1.0.

vladimiry avatar May 19 '21 15:05 vladimiry

Not sure I understand the issue, as we're using 3.1.0 in the lockfile:

https://github.com/atom/node-keytar/blob/12484088ce0980a903627b6fc7ddaaf02188e982/package-lock.json#L2206-L2210

And our dependency is not 3.2.0 specifically:

https://github.com/atom/node-keytar/blob/12484088ce0980a903627b6fc7ddaaf02188e982/package.json#L53

There's some extra context here about how we're prebuild-ing for N-API now https://github.com/atom/node-keytar/pull/331 so I'm not sure if that's somehow affected things

shiftkey avatar May 19 '21 16:05 shiftkey

I was also able to do this successfully with the latest version on macOS (using our version of node-gyp, not the global one):

$ ./node_modules/.bin/node-gyp rebuild --target=13.0.0-beta.27 --arch=x64 --dist-url=https://electronjs.org/headers
gyp info it worked if it ends with ok
gyp info using [email protected]
gyp info using [email protected] | darwin | x64
gyp info find Python using Python version 3.9.5 found at "/usr/local/opt/[email protected]/bin/python3.9"
gyp http GET https://electronjs.org/headers/v13.0.0-beta.27/node-v13.0.0-beta.27.tar.gz
gyp http 200 https://electronjs.org/headers/v13.0.0-beta.27/node-v13.0.0-beta.27.tar.gz
gyp http GET https://electronjs.org/headers/v13.0.0-beta.27/SHASUMS256.txt
gyp http 200 https://electronjs.org/headers/v13.0.0-beta.27/SHASUMS256.txt
gyp info spawn /usr/local/opt/[email protected]/bin/python3.9
gyp info spawn args [
gyp info spawn args   '/Users/shiftkey/src/node-keytar/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/shiftkey/src/node-keytar/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/shiftkey/src/node-keytar/node_modules/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/shiftkey/Library/Caches/node-gyp/13.0.0-beta.27/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/shiftkey/Library/Caches/node-gyp/13.0.0-beta.27',
gyp info spawn args   '-Dnode_gyp_dir=/Users/shiftkey/src/node-keytar/node_modules/node-gyp',
gyp info spawn args   '-Dnode_lib_file=/Users/shiftkey/Library/Caches/node-gyp/13.0.0-beta.27/<(target_arch)/node.lib',
gyp info spawn args   '-Dmodule_root_dir=/Users/shiftkey/src/node-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 ]
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
  CXX(target) Release/obj.target/keytar/src/async.o
  CXX(target) Release/obj.target/keytar/src/main.o
  CXX(target) Release/obj.target/keytar/src/keytar_mac.o
  SOLINK_MODULE(target) Release/keytar.node
gyp info ok

shiftkey avatar May 19 '21 16:05 shiftkey

Not sure I understand the issue, as we're using 3.1.0 in the lockfile:

Lock file doesn't make sense if the module is installed from npm (since lock files don't get published to npm), so the new node-addon-api version got into the game by "node-addon-api": "^3.0.0" range. I just don't use prebuilds and this is how the issue got noticed.

I was also able to do this successfully with the latest version on macOS (using our version of node-gyp, not the global one):

I've tried both 8.0.0 (globally installed) and ./node_modules/.bin/node-gyp (7.1.2), the result is the same. Try it with [email protected].

latest version on macOS

Maybe the issue is OS-specific. I don't have macOS system to test it in my own.

vladimiry avatar May 19 '21 16:05 vladimiry

I'm having the same problem; I think it only fails with newer versions of node. With node 14.11.0 installed, I can build successfully; with later versions, it fails.

14.12.0 15.12.0 is the first version to support NAPI v8 (source), and the node-addon-api commit that introduced the error is conditioned on v8 being available: https://github.com/nodejs/node-addon-api/commit/77350eee98957f471a355a4cf12f6ee05262fa5b. However, I still don't really understand why it fails with NAPI v8.

@shiftkey - if you install the latest version of node and then try to build, can you see the issue?

PalmerAL avatar Jun 11 '21 20:06 PalmerAL

I'm on Node v14.17.1 and I have the same problem @PalmerAL

gaetandezeiraud avatar Jun 25 '21 10:06 gaetandezeiraud

I just pinned keytar/[email protected] as a workaround for use with node 15.

vladimiry avatar Jul 01 '21 17:07 vladimiry

Btw, node-addon-api v4 was released about 2 weeks ago and it's also affected.

vladimiry avatar Jul 02 '21 08:07 vladimiry

I was having this issue on Windows with node 14.17.1 - I found the error does not occur with keytar version 7.6.0 so it seems to be something in the 7.7.0 release.

Wiltuk avatar Jul 02 '21 19:07 Wiltuk

@Wiltuk I have the same problem with keytar 7.6.0 on my side. Event after deleting node_modules and lock file.

gaetandezeiraud avatar Jul 06 '21 15:07 gaetandezeiraud

+1 have this exact issue on macOS. Can fix by running on node 14 <= 14.16.1, but our team needs 15+ for ARM builds of our electron application. Any insight on this would be highly appreciated

EDIT: It seems that what @PalmerAL said is spot on. Using Node 15 <15.12.0 works fine, so it must be something with NAPIv8 is causing this.

felipe-linares avatar Jul 12 '21 20:07 felipe-linares

No workaround with the lastest LTS version of node?

gaetandezeiraud avatar Jul 14 '21 08:07 gaetandezeiraud

@Brouilles see the issue title, ie downgrading node-addon-api to 3.1.0 is a workaround.

vladimiry avatar Jul 14 '21 08:07 vladimiry

Any update on this? Some of our other dependencies (lodash in particular) don't support node 15, only node 14/16. But we need 15+ for ARM builds so 16 would be our only option, but because of node-addon-api issues it doesn't work on node 16...

felipe-linares avatar Jul 27 '21 21:07 felipe-linares

@vladimiry , I am also facing the same issue. I updated the keytar version from 7.3.0 to 7.7.0. I also installed node-addon-api version 3.1.0. But still I am facing the same issue. May I know what was your work around?

Ranjith-Eswaran-G avatar Dec 16 '21 07:12 Ranjith-Eswaran-G

May I know what was your work around?

The workaround was in downgrading node-addon-api to 3.1.0 but I removed downgrade in my project some time ago as the issue got fixed somewhere upstream (currently used node-addon-api is 3.2.1).

So I believe the issue can be closed now.

vladimiry avatar Dec 16 '21 07:12 vladimiry

The workaround was in downgrading node-addon-api to 3.1.0 but I removed downgrade in my project some time ago as the issue got fixed somewhere upstream

May I know your current Electron and Node version?

Ranjith-Eswaran-G avatar Dec 16 '21 07:12 Ranjith-Eswaran-G

Node 16.13.1 and @electron 15.3.2 & 17.0.0-alpha.4 (was fine on @electron v16 too).

vladimiry avatar Dec 16 '21 07:12 vladimiry

Thanks for your response. But I am getting the error you mentioned at the top even after downgrading node-addon-api to 3.1.0. It works fine only when I use the node version 14.11.0.

Ranjith-Eswaran-G avatar Dec 16 '21 07:12 Ranjith-Eswaran-G

I guess node-gyp version also might be a part of the stack, at my side it's [email protected].

vladimiry avatar Dec 16 '21 08:12 vladimiry