electron: [Bug]: Native modules that include nan.h fail to build on electron 20
Preflight Checklist
- I have read the Contributing Guidelines for this project.
- I agree to follow the Code of Conduct that this project adheres to.
- I have searched the issue tracker for a bug report that matches the one I want to file, without success.
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

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
- TF-255: Update build for Electron 20 This commit updates the module to cause it to build for electron 20; - Increase C++ version to C++17 - Merge upstream node16 changes - Temporarily use forked ver... — committed to fourieraudio/node-capnp by p--b 2 years ago
- TF-255: Update build for Electron 20 This commit updates the module to cause it to build for electron 20; - Increase C++ version to C++17 - Merge upstream node16 changes - Temporarily use forked ver... — committed to fourieraudio/node-capnp by p--b 2 years ago
- TF-255: Update build for Electron 20 This commit updates the module to cause it to build for electron 20; - Increase C++ version to C++17 - Merge upstream node16 changes - Use latest version of `nan... — committed to fourieraudio/node-capnp by p--b 2 years ago
- TF-255: Update build for Electron 20 This commit updates the module to cause it to build for electron 20; - Increase C++ version to C++17 - Merge upstream node16 changes - Use latest version of `nan... — committed to fourieraudio/node-capnp by p--b 2 years ago
- deps: Upgrade nan to v2.17.0 This version fixes compiling native addons with Electron v20+. See https://github.com/electron/electron/issues/35193. — committed to cozy-labs/cozy-desktop by taratatach a year ago
- deps: Upgrade nan to v2.17.0 This version fixes compiling native addons with Electron v20+. See https://github.com/electron/electron/issues/35193. — committed to cozy-labs/cozy-desktop by taratatach a year ago
Was/am facing similar issues as well. We don’t use yarn, just npm, so I ended up trying:
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 ofgithub: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?: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
and overriding
nan
to:did the trick, at least for
electron-rebuild
@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):
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:We have the same Problem in electron 20 with “nan”…
…and also “CreationContext” https://github.com/WiseLibs/better-sqlite3/issues/858
"CreationContext" is no member of "v8::Object"
cc @VerteDinde