electron: [Bug]: Native modules that include nan.h fail to build on electron 20

Preflight Checklist

Electron Version

20.0.0

What operating system are you using?

macOS

Operating System Version

monterey

What arch are you using?

arm64 (including Apple Silicon)

Last Known Working Electron version

Latest v19

Expected Behavior

Native modules to install correctly

Actual Behavior

I’ve seen this behavior on two different node modules when they #include <nan.h> so it seems independent from the implementations in the modules. It seems to be triggered by just including nan.h when electron-gyp goes to build the module. Are modules no longer allowed to include nan.h or is this a bug inside electron? Thanks!

I’ll also note both the modules I mention are pointed to nan v2.16.0

image

Testcase Gist URL

Here is an example package.json. Running npm i triggers the aforementioned error.

{                                                                                                                                   
  "scripts": {                                                                                                                      
    "postinstall": "electron-rebuild -f -w node-pty"                                                                                
  },                                                                                                                                
  "dependencies": {                                                                                                                 
    "node-pty": "0.11.0-beta20"                                                                                                     
  },                                                                                                                                
  "devDependencies": {                                                                                                              
    "electron": "^20.0.0",                                                                                                          
    "electron-rebuild": "^3.2.9"                                                                                                    
  }                                                                                                                                 
}

Additional Information

No response

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 27
  • Comments: 22 (8 by maintainers)

Commits related to this issue

Most upvoted comments

Was/am facing similar issues as well. We don’t use yarn, just npm, so I ended up trying:

  "overrides": {
    "nan": "github:jkleinsc/nan#remove_accessor_signature"
  },

in package.json and it worked well. Will continue following this issue for updates on things. Thanks for all of the support and work!

Update 9/21: the GitHub/git branch the above is pointing to no longer exists. It sounds like github:tec27/nan#remove_accessor_signature is a good recreation of github:jkleinsc/nan#remove_accessor_signature. That said, I encourage everyone to actually look at the branch you choose to install. The person who owns the branch can commit whatever code they want. So make sure to verify you are installing something safe, whatever it is you choose to install. Alternatively you can fork nan and recreate the original branch yourself (this PR shows what the changes were) so things are more in your control.

Shoot, I know what this is 😕 Sorry @npezza93, here’s what’s happening - AccessorSignatures was deprecated in Chromiuim in this CL, which was included in Electron 20. We’ve made an upstream PR to similarly remove AccessorSignatures from nan itself: https://github.com/nodejs/nan/pull/941 However, it looks like that PR has stalled.

The presence of the deprecated AccessorSignatures specifically is why your module is failing to build. We’ll need to get that upstream PR merged and a new version of nan released in order to fix the issue.

Can you try adding this to your package’s package.json and see if it resolves the issue for you temporarily?:

  "resolutions": {
    "nan": "github:jkleinsc/nan#remove_accessor_signature"
  },

I’ll see if we can find a more suitable workaround for this while we wait for the upstream PR to land, so devs don’t have to use this hack. 🙇‍♀️ Thanks for reporting this!

I can confirm that this issue is fixed in the latest nan version, so I’m closing this issue. Feel free to let me know if anyone is still facing this, then I will reopen it. Thanks everyone! 🎉

On our side, as was mentioned. Putting this on binding.gyp

'xcode_settings': {
    'CLANG_CXX_LANGUAGE_STANDARD': 'c++17'
}

and overriding nan to:

    "nan": "github:tec27/nan#remove_accessor_signature",

did the trick, at least for electron-rebuild

Hey @VerteDinde!

That resolution may have fixed it. There are circumstances where I can get the attached error to show up, though which is different. Not sure if it is related or a different issue. If I use electron-rebuild, that resolution seems to fix it, but if I use electron-builder with ./node_modules/.bin/electron-builder install-app-deps this trigger happens. I can give a package.json that’s reproducible if that will help.

image

@npezza93 We had the same issue. Check that you’re compiling with C++ >= 17 … we had to add the following in our binding.gyp (on macOS):

'xcode_settings': {
    'CLANG_CXX_LANGUAGE_STANDARD': 'c++17'
}
"resolutions": {
  "nan": "github:tec27/nan#remove_accessor_signature"
}

Fixes it for me for the time being. Thanks everyone!

For people like us who still builds Linux releases on old Ubuntu 16.04 (for compatibility purposes). is_lvalue_reference requires g++ >= 7.5.0, which can be installed with:

sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
sudo apt-get update
sudo apt-get install gcc-7 g++-7 -y
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 70 --slave /usr/bin/g++ g++ /usr/bin/g++-7

We have the same Problem in electron 20 with “nan”…

node_modules\nan\nan_callbacks.h(55,23): error C2039: "AccessorSignature" ist kein Member von "v8"
node_modules\nan\nan_callbacks.h(55,40): error C2065: "AccessorSignature": nichtdeklarierter Bezeichner
node_modules\nan\nan_callbacks.h(55,13): error C2923: "v8::Local": "AccessorSignature" ist kein gültiges Vorlage-Typargument
node_modules\nan\nan.h(2546,6): error C2664: "void v8::ObjectTemplate::SetAccessor(v8::Local<v8::String>,...
...

…and also “CreationContext” https://github.com/WiseLibs/better-sqlite3/issues/858

"CreationContext" is no member of "v8::Object"

void Init(v8::Local<v8::Object> exports)
{
    v8::Local<v8::Context> context = exports->CreationContext();