Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Cannot compile native modules using nan against Electron v29 #41518

Closed
3 tasks done
JasonYeMSFT opened this issue Mar 6, 2024 · 3 comments
Closed
3 tasks done
Labels

Comments

@JasonYeMSFT
Copy link

Preflight Checklist

Electron Version

29.1.0

What operating system are you using?

macOS

Operating System Version

14.3.1

What arch are you using?

arm64 (including Apple Silicon)

Last Known Working Electron version

28.2.2

Expected Behavior

My project compiles a few native modules against Electron using nan. The compilation should work.

Actual Behavior

The compilation doesn't work and reports the following error:

npm ERR! ../../nan/nan.h:2548:8: error: no matching member function for call to 'SetAccessor'
npm ERR!   tpl->SetAccessor(
npm ERR!   ~~~~~^~~~~~~~~~~
npm ERR! /Users/my_username/.electron-gyp/Library/Caches/node-gyp/29.1.0/include/node/v8-template.h:806:8: note: candidate function not viable: no known conversion from 'v8::AccessControl' to 'PropertyAttribute' for 5th argument
npm ERR!   void SetAccessor(

Testcase Gist URL

No response

Additional Information

Compiling the same native module code against Node works. Electron 29 uses Node 20.9.0. However, the v8-template.h file that is used to compile the native module to Electron v29 is different from the v8-template.h file that is used to compile the native module to Node v20.9.0.

Electron v29.1.0's v8-template.h at line 800

  void SetAccessor(
      Local<String> name, AccessorGetterCallback getter,
      AccessorSetterCallback setter = nullptr,
      Local<Value> data = Local<Value>(), PropertyAttribute attribute = None,
      SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
      SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
  void SetAccessor(
      Local<Name> name, AccessorNameGetterCallback getter,
      AccessorNameSetterCallback setter = nullptr,
      Local<Value> data = Local<Value>(), PropertyAttribute attribute = None,
      SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
      SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);

Node v20.9.0's v8-template.h at line 809

  void SetAccessor(
      Local<String> name, AccessorGetterCallback getter,
      AccessorSetterCallback setter = nullptr,
      Local<Value> data = Local<Value>(), AccessControl settings = DEFAULT,
      PropertyAttribute attribute = None,
      SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
      SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
  void SetAccessor(
      Local<Name> name, AccessorNameGetterCallback getter,
      AccessorNameSetterCallback setter = nullptr,
      Local<Value> data = Local<Value>(), AccessControl settings = DEFAULT,
      PropertyAttribute attribute = None,
      SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
      SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);

This discrepancy seems to be the cause of the error. In fact, v8-template.h for Node v21.6.2 also contains the AccessControl argument. My search indicates that the code change was made in this PR in Nov. 2023, which is prior to both the release date of Node v21.6.2 and Electron v29.1.0. I don't know why there would be such discrepancy in their header files. I am opening this issue in the Electron repo instead of the nan repo because Node's header files seem to be keeping the AccessControl argument. The author of "nan" cannot simply change their usage of the API because that would break native modules targeting Node.

@MarshallOfSound
Copy link
Member

This is an upstream nan issue, Electron is occasionally on newer versions of V8 than node is. Nan still needs to update their code to support the newer v8 version eventually.

In this case this has already been fixed upstream but has not been released yet. --> nodejs/nan#966

Related though, you should avoid native modules that depend on nan. It is unsafe in general, even more-so in Electron. Native modules should be built depending on napi instead nowadays as it is substantially safer (and doesn't have these v8 drift issues)

@MarshallOfSound MarshallOfSound closed this as not planned Won't fix, can't repro, duplicate, stale Mar 6, 2024
@beshkenadze
Copy link

@MarshallOfSound How can we avoid using sqlite3?

@ufukomer
Copy link

Same here. I had to revert to electron v28.

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

No branches or pull requests

4 participants