Skip to content

Electron 33 broken #978

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

Closed
danielweck opened this issue Oct 16, 2024 · 20 comments · May be fixed by #979
Closed

Electron 33 broken #978

danielweck opened this issue Oct 16, 2024 · 20 comments · May be fixed by #979

Comments

@danielweck
Copy link

The latest NAN release works fine in Electron 32, but now fails with:

In file included from ../node_modules/nan/nan.h:3045:
../node_modules/nan/nan_scriptorigin.h:40:7: error: no matching constructor for initialization of 'v8::ScriptOrigin'
   40 |       v8::ScriptOrigin(v8::Isolate::GetCurrent()
      |       ^                ~~~~~~~~~~~~~~~~~~~~~~~~~
   41 |                    , name
      |                    ~~~~~~
   42 |                    , To<int32_t>(line).FromMaybe(0)) {}
../node_modules/nan/nan_scriptorigin.h:47:7: error: no matching constructor for initialization of 'v8::ScriptOrigin'
   47 |       v8::ScriptOrigin(v8::Isolate::GetCurrent()
      |       ^                ~~~~~~~~~~~~~~~~~~~~~~~~~
   48 |                    , name
      |                    ~~~~~~
   49 |                    , To<int32_t>(line).FromMaybe(0)
      |                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   50 |                    , To<int32_t>(column).FromMaybe(0)) {}

../node_modules/nan/nan_scriptorigin.h:36:7: error: no matching constructor for initialization of 'v8::ScriptOrigin'
   36 |       v8::ScriptOrigin(v8::Isolate::GetCurrent(), name) {}
      |       ^                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/qwe/Library/Caches/node-gyp/33.0.0/include/node/v8-message.h:64:13: note: candidate constructor not viable: no known conversion from 'Isolate *' to 'Local<Value>' for 1st argument
   64 |   V8_INLINE ScriptOrigin(Local<Value> resource_name,
      |             ^            ~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/qwe/Library/Caches/node-gyp/33.0.0/include/node/v8-message.h:62:17: note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 2 were provided
   62 | class V8_EXPORT ScriptOrigin {
      |                 ^~~~~~~~~~~~
/Users/qwe/Library/Caches/node-gyp/33.0.0/include/node/v8-message.h:62:17: note: candidate constructor (the implicit move constructor) not viable: requires 1 argument, but 2 were provided
   62 | class V8_EXPORT ScriptOrigin {
      |                 ^~~~~~~~~~~~
@danielweck
Copy link
Author

@danielweck
Copy link
Author

Electron 33 ships with Node 20.18.0:

https://github.com/electron/electron/releases/tag/v33.0.0

@agracio
Copy link

agracio commented Oct 16, 2024

Electron 33 moved to v8 13.0 while Node.js main is currently on v8 12.9, perhaps someone can create a working fork that addresses the problem?
Unless by some miracle Node.js moves to v8 13.0 for its v23 release I do not think nan will address the issue themselves.

@danielweck
Copy link
Author

Great point @agracio ... pinging @toshiyuki-rs @oc-soft @kkoopa @bugsounet

@agracio
Copy link

agracio commented Oct 16, 2024

You should not ping nan maintainers as they have been quick to point out that they do not support and have no intention to support Electron in the future.

@danielweck
Copy link
Author

danielweck commented Oct 16, 2024

Apologies, I thought you were the NAN maintainer :) 👍 (very quick response indeed, thank you)

Well, my workaround is to comment #include nan_scriptorigin.h in nan.h:

nan/nan.h

Line 3045 in f5921c7

#include "nan_scriptorigin.h" // NOLINT(build/include)

(I do this with sed from my package.json postinstall)

Closing the issue now.

@kkoopa
Copy link
Collaborator

kkoopa commented Oct 16, 2024

It is probably this commit. 0151569 I will get around to it at some future time.

@agracio
Copy link

agracio commented Oct 16, 2024

Thanks!

@agracio
Copy link

agracio commented Oct 16, 2024

@danielweck could you share your package.json script with postinstall

@kkoopa
Copy link
Collaborator

kkoopa commented Oct 16, 2024

And can someone with Electron 33 confirm that applying 0151569 resolves the issue?

@agracio
Copy link

agracio commented Oct 16, 2024

Will do but give me about 30+ minutes.

@danielweck
Copy link
Author

@danielweck could you share your package.json script with postinstall

Not pretty, quick and dirty, but works in MacOS and Linux:

"postinstall": "sed 's/^#include .nan_scriptorigin\\.h./\\/\\/ #include nan_scriptorigin.h/' ./node_modules/nan/nan.h > ./node_modules/nan/nan.h.new && mv ./node_modules/nan/nan.h.new ./node_modules/nan/nan.h"

@agracio
Copy link

agracio commented Oct 16, 2024

And can someone with Electron 33 confirm that applying 0151569 resolves the issue?

It absolutely does, tested Electron 29, 30, 31, 32 and 33 that are supported by nan 2.22.

@agracio
Copy link

agracio commented Oct 17, 2024

@kkoopa So is it just a issue of merging that commit and everything will be working?

yuvalkarmi added a commit to glitter-ai/iohook that referenced this issue Jan 5, 2025
aadcg added a commit to atlas-engineer/cl-electron that referenced this issue Jan 30, 2025
synchronous-socket depends on nan, which needs to be patched for Electron >= 33.
For the complete discussion and a hotfix see:

nodejs/nan#978 (comment)

Hopefully a PR that fixes it will be merged soon, nodejs/nan#979.

Closes #56.
@ayZagen
Copy link

ayZagen commented Feb 9, 2025

@danielweck this issue is still valid and should be open until a fix is landed

@agracio
Copy link

agracio commented Feb 28, 2025

The issue is not present in nan v2.22.2 tested with electron 29-34 as well as 35 beta and latest 36 nightly.

@oalfroukh
Copy link

oalfroukh commented Mar 2, 2025

Apologies, I thought you were the NAN maintainer :) 👍 (very quick response indeed, thank you)

Well, my workaround is to comment #include nan_scriptorigin.h in nan.h:

nan/nan.h

Line 3045 in f5921c7

#include "nan_scriptorigin.h" // NOLINT(build/include)
(I do this with sed from my package.json postinstall)

Closing the issue now.

Hi @danielweck
But this postinstall will not work fine in case using nan by subDependencies, so I think this issue should be reopened as needs a fix...
Anyone can take a look at it, please?

EDIT:
The issue is fixed on nan v2.22.2 so overrides the version to the latest version that's released 4 days ago(`v2.22.2) will fix the issue.

@agracio
Copy link

agracio commented Mar 2, 2025

While the issue is solved in nan v2.22.2 postinstall overrides can be easily applied for sub dependencies.
Here is a sample script from my repo:

updatenan.js

const spawn = require('child_process').spawn
const existsSync = require('fs').existsSync
const nanPath = existsSync('./node_modules/nan/nan.h') ? './node_modules/nan/nan.h' : '../nan/nan.h'

if(existsSync(nanPath)){
    if (process.platform === 'win32') {
        spawn('powershell', ['-Command', `(Get-Content -Raw ${nanPath}) -replace '#include \"nan_scriptorigin.h\"', '// #include \"nan_scriptorigin.h\"' | Out-File -Encoding Utf8 ${nanPath}`], { stdio: 'inherit' })
    } else {
        spawn('sed', ['-i', '-e', 's/^#include .nan_scriptorigin\\.h./\\/\\/ #include nan_scriptorigin.h/', nanPath], { stdio: 'inherit' })
    }

}

@oalfroukh
Copy link

While the issue is solved in nan v2.22.2 postinstall overrides can be easily applied for sub dependencies. Here is a sample script from my repo:

updatenan.js

const spawn = require('child_process').spawn
const existsSync = require('fs').existsSync
const nanPath = existsSync('./node_modules/nan/nan.h') ? './node_modules/nan/nan.h' : '../nan/nan.h'

if(existsSync(nanPath)){
if (process.platform === 'win32') {
spawn('powershell', ['-Command', (Get-Content -Raw ${nanPath}) -replace '#include \"nan_scriptorigin.h\"', '// #include \"nan_scriptorigin.h\"' | Out-File -Encoding Utf8 ${nanPath}], { stdio: 'inherit' })
} else {
spawn('sed', ['-i', '-e', 's/^#include .nan_scriptorigin\.h./\/\/ #include nan_scriptorigin.h/', nanPath], { stdio: 'inherit' })
}

}

Also just adding overrides to the package.json should fix the issue for sub dependencies instead of using scripts

,
  "overrides": {
    "nan": "2.22.2"
  }

@agracio
Copy link

agracio commented Mar 3, 2025

I removed that script from my repo since the release of nan v2.22.2 just wanted to show a PoC of install/postinstall script that works for sub dependencies. Cannot even take a credit for it as it was a PR from one of the repo contributors.

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

Successfully merging a pull request may close this issue.

5 participants