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

Error with Electron and ffi-napi #238

Open
Tracked by #4580
Jey0707 opened this issue Jan 21, 2023 · 58 comments
Open
Tracked by #4580

Error with Electron and ffi-napi #238

Jey0707 opened this issue Jan 21, 2023 · 58 comments

Comments

@Jey0707
Copy link

Jey0707 commented Jan 21, 2023

Electron: ^22.0.3
Tried also with Electron 20.0.0
ffi-napi: 4.0.3

File index.js

const { app, BrowserWindow } = require('electron')
var ffi = require('ffi-napi');


const createWindow = () => {
    const win = new BrowserWindow({
        width: 800,
        height: 600
    })

    win.loadFile('index.html')
}


app.whenReady().then(() => {
    createWindow()
})


var libm = ffi.Library('libm', {
    'ceil': ['double', ['double']]
});
libm.ceil(1.5); // 2

// You can also access just functions in the current process by passing a null
var current = ffi.Library(null, {
    'atoi': ['int', ['string']]
});
current.atoi('1234'); // 1234

File index.html

<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP -->
    <meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'">
    <title>Hello World!</title>
</head>

<body>
    <h1>Hello World!</h1>
    We are using Node.js <span id="node-version"></span>,
    Chromium <span id="chrome-version"></span>,
    and Electron <span id="electron-version"></span>.
</body>

</html>

Error:

App threw an error during load
Error: Error in native callback
    at process.func [as dlopen] (node:electron/js2c/asar_bundle:2:1822)
    at Module._extensions..node (node:internal/modules/cjs/loader:1226:18)
    at Object.func [as .node] (node:electron/js2c/asar_bundle:2:1822)
    at Module.load (node:internal/modules/cjs/loader:1011:32)
    at Module._load (node:internal/modules/cjs/loader:846:12)
    at f._load (node:electron/js2c/asar_bundle:2:13330)
    at Module.require (node:internal/modules/cjs/loader:1035:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at load (C:\Users\Farella Vito\Desktop\Instance Manager v2\node_modules\node-gyp-build\node-gyp-build.js:22:10)
    at Object.<anonymous> (C:\Users\Farella Vito\Desktop\Instance Manager v2\node_modules\ref-napi\lib\ref.js:8:53)
@Stayer
Copy link

Stayer commented Jan 25, 2023

same problem, electron 22.0.2 and ffi-napi 4.0.3

@paulyu12
Copy link

same problem, electron 22.0.3 and ffi-npi 4.0.3

@feralresearch
Copy link

I am seeing a similar stack trace using electron 22.0.3 when importing a module which uses ffi-napi 4.0.3. I was able to get it working by downgrading electron to 20.0.2 (I tried that specific version because I came across this SO).

  • The closest stable release above that (20.3.11) fails

  • The closest stable release below that (19.1.9) runs ok.

node:electron/js2c/asar_bundle:5
    at process.func [as dlopen] (node:electron/js2c/asar_bundle:5:1812)
    at Module._extensions..node (node:internal/modules/cjs/loader:1205:18)
    at Object.func [as .node] (node:electron/js2c/asar_bundle:5:1812)
    at Module.load (node:internal/modules/cjs/loader:988:32)
    at Module._load (node:internal/modules/cjs/loader:829:12)
    at c._load (node:electron/js2c/asar_bundle:5:13343)
    at Module.require (node:internal/modules/cjs/loader:1012:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at load (C:\Users\***\node_modules\node-gyp-build\node-gyp-build.js:22:10)
    at Object.<anonymous> (C:\Users\***\node_modules\ref-napi\lib\ref.js:8:53)`

@hatsune-miku
Copy link

hatsune-miku commented Jan 30, 2023

Update: locking electron version to 20.0.0 worked for me.

  1. Write "electron": "20.0.0", (without caret^) in package.json
  2. Run a yarn install or equivalent and you will see electron is re-compiling
  3. It works. Just spent a whole day on it

PS: I have seen some tutorials saying you should run node-gyp or electron-rebuild manually to get it worked but actually you don't have to. I only did yarn add ffi-napi.
PS: My project is newly created by yarn create electron-vite project_name --template typescript


Same problem on both electron 20.0.0 and 20.0.2. "ffi-napi": "^4.0.3".

Uncaught Error: Error in native callback
    at process.func [as dlopen]
    ...

at the line const ffi = require('ffi-napi')

@ClaudioMuselli90
Copy link

same problem, electron 22.1.0 and ffi-napi 4.0.3

@HeiSir2014
Copy link

same problem, osx 13.2, electron 22 and ffi-napi 4.0.3

@vyach-vasiliev
Copy link

vyach-vasiliev commented Feb 4, 2023

The same problem. I used template like @hatsune-miku
TypeScript, Vite, Electron
Win10, npm v9.4.0, node v16.15.1

{
    "electron": "^22.2.0",
    "ffi-napi": "^4.0.3",
    "ref-napi": "^3.0.3",
}

I also found out that the latest compatible electron version is equal to 20.3.8.
And starting from the electron version 20.3.9 the application crashes with an error.

Maybe this comparison will help knowledgeable people to understand the problem:
electron/electron@v20.3.8...v20.3.9

@dontpanic5
Copy link

Maybe this comparison will help knowledgeable people to understand the problem:
electron/electron@v20.3.8...v20.3.9

I don't claim to be knowledgeable but I peeked at this out of curiosity. Whatever changed in Electron to make this behavior start, it would most likely be related to Node.js. The only issue that's related to Node.js is this: electron/electron#36626.
That issue is related to this issue in the Electron repo: electron/electron#35801 which is also about native modules ceasing to function.
I'm still working to wrap my head around the "memory cages" issue that Electron 35801 is about, so that's as far as I've gotten.

@2BC-Wasabi
Copy link

same issue here when trying to upgrade from electron 18.2.3 to 20 all the way to 23

@ej-toita
Copy link

same issue on WIn10, npm 8.19.2, node 18.12.1
In my case i do not use vite, but just as @vyach-vasiliev I found out that it fails on electron 20.3.9 or later.

@ej-toita
Copy link

correct me if I am wrong, but is the below what we want?

Introduce Napi::Buffer::NewOrCopy to create buffer from external buffers that are compatible with runtimes like electron conveniently.
nodejs/node-addon-api#1273 (comment)

@dontpanic5
Copy link

Yes that seems to be the fix for the runtime error.
Someone forked ref-napi (dependency of ffi-napi) and made the same change separately here:
node-ffi-napi/ref-napi@latest...Vitalii4as:ref-napi:latest

@2BC-Wasabi
Copy link

how do i install that fix ?

@Galkon
Copy link

Galkon commented Mar 3, 2023

Yes that seems to be the fix for the runtime error. Someone forked ref-napi (dependency of ffi-napi) and made the same change separately here: node-ffi-napi/ref-napi@latest...Vitalii4as:ref-napi:latest

Thanks for pointing this out! Would love to see this merged and released in ref-napi and a subsequent ffi-napi release so we don't have to fork and build our own versions.

@ej-toita
Copy link

ej-toita commented Mar 6, 2023

@Vitalii4as Would you kindly make the pull request to the official ref-napi repo for us?

@yoshiok
Copy link

yoshiok commented Mar 7, 2023

I'm in trouble too. I was wondering if there is another good library and I found this one. i will try.
koffi

@Vitalii4as
Copy link

Vitalii4as commented Mar 7, 2023

@ej-toita My fix didn't work(

@lwahonen
Copy link

lwahonen commented Mar 9, 2023

These two are working for me:

https://www.npmjs.com/package/@lwahonen/ffi-napi
https://www.npmjs.com/package/@lwahonen/ref-napi

For some reason I need to npm install twice on Windows, as the first build always poops out with "file in use" errors. Feel free to figure out why that happens.

@Galkon
Copy link

Galkon commented Mar 13, 2023

These two are working for me:

https://www.npmjs.com/package/@lwahonen/ffi-napi https://www.npmjs.com/package/@lwahonen/ref-napi

For some reason I need to npm install twice on Windows, as the first build always poops out with "file in use" errors. Feel free to figure out why that happens.

I can confirm these versions are working for me as well. Big thanks to @lwahonen -- but I would hope to see the fixes merged into the mainline ffi-napi and ref-napi repositories. But since these seem largely unmaintained, maybe we should accept that a new fork is necessary 😢

@2BC-Wasabi
Copy link

i get this error when trying to install

These two are working for me:

https://www.npmjs.com/package/@lwahonen/ffi-napi https://www.npmjs.com/package/@lwahonen/ref-napi

For some reason I need to npm install twice on Windows, as the first build always poops out with "file in use" errors. Feel free to figure out why that happens.

npm ERR!   nothing.c
npm ERR! C:\Users\Wasabi\Desktop\Electron_react_boilerPlate_testNapi\release\app\node_modules\node-addon-api\nothing.c : fatal error C1083: Cannot open compiler generated file: 'C:\Users\Wasabi\Desktop\Electron_react_boilerPlate_testNapi\release\app\node_modules\@lwahonen\node-addon-api\Release\obj\nothing\node-addon-api\nothing.obj': Permission denied [C:\Users\Wasabi\Desktop\Electron_react_boilerPlate_testNapi\release\app\node_modules\@lwahonen\node-addon-api\nothing.vcxproj]
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@9.3.1
npm ERR! gyp info using node@18.15.0 | win32 | x64
npm ERR! gyp info find Python using Python version 3.10.9 found at "C:\Python310\python.exe"
npm ERR! gyp info find VS using VS2019 (16.11.33130.400) found at:
npm ERR! gyp info find VS "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools"

@lwahonen
Copy link

i get this error when trying to install

These two are working for me:
https://www.npmjs.com/package/@lwahonen/ffi-napi https://www.npmjs.com/package/@lwahonen/ref-napi
For some reason I need to npm install twice on Windows, as the first build always poops out with "file in use" errors. Feel free to figure out why that happens.

npm ERR!   nothing.c
npm ERR! C:\Users\Wasabi\Desktop\Electron_react_boilerPlate_testNapi\release\app\node_modules\node-addon-api\nothing.c : fatal error C1083: Cannot open compiler generated file: 'C:\Users\Wasabi\Desktop\Electron_react_boilerPlate_testNapi\release\app\node_modules\@lwahonen\node-addon-api\Release\obj\nothing\node-addon-api\nothing.obj': Permission denied [C:\Users\Wasabi\Desktop\Electron_react_boilerPlate_testNapi\release\app\node_modules\@lwahonen\node-addon-api\nothing.vcxproj]
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@9.3.1
npm ERR! gyp info using node@18.15.0 | win32 | x64
npm ERR! gyp info find Python using Python version 3.10.9 found at "C:\Python310\python.exe"
npm ERR! gyp info find VS using VS2019 (16.11.33130.400) found at:
npm ERR! gyp info find VS "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools"

As I said, you need to run npm install twice. Feel free to figure out what’s blocking the access to nothing.obj on the first go.

@2BC-Wasabi
Copy link

i tried multiple times, but same result :\

@Galkon
Copy link

Galkon commented Mar 19, 2023

As I said, you need to run npm install twice. Feel free to figure out what’s blocking the access to nothing.obj on the first go.

For what it's worth, it appears to work in one go using pnpm @lwahonen

@xmsz
Copy link

xmsz commented Mar 28, 2023

any update?

@lwahonen
Copy link

any update?

I don't think any updates are going to be happening. I patched the fix from @inigolabs enough that it works for us. If you look at the commit history on this repo, nobody has been working on node-ffi-napi for a long time.

@whlll-coder
Copy link

change to electron@15.4.0 & ffi-napi@4.0.3 can fix it

@Galkon
Copy link

Galkon commented Apr 12, 2023

change to electron@15.4.0 & ffi-napi@4.0.3 can fix it

The solution should not be to downgrade your electron. It is important to stay up to date with the latest electron for many reasons.

@wansongtao
Copy link

same problem, electron 21.4.4 and ffi-napi 4.0.3

@WoJiaoFuXiaoYun
Copy link

Same question

"electron": "^24.1.3"

I will change it to

"electron": "20.0.2"

Successfully run

@ej-toita
Copy link

ej-toita commented Jul 20, 2023

I finally got some time to try

 "electron": "^25.3.1",
 "@breush/ffi-napi": "^4.0.13",
 "@breush/ref-napi": "^4.0.9"

myself, and it caused
no native build was found for platform=win32 arch=x64 runtime=electron error.
@electron/rebuild did no good.

@stevenlafl
Copy link

stevenlafl commented Aug 9, 2023

I got this working with @Breush 's packages. Now the problem is that when the electron app is packaged as an ASAR, any dependent DLLs inside cannot be loaded. I just get Win32 Error 126, which is related to not being able to load a library.

node-ffi/node-ffi#294 (comment)

The simplest way around this without having to hack node dependencies which package compiled libs to pieces.. is to use

module.exports = {
  packagerConfig: {
    asar: false,
    ...
  },
  ...
}
...

@et-hh
Copy link

et-hh commented Sep 1, 2023

@Breush can you prebuild for ia32 in your pkg?
i can use your pkg in dev. but myapp is build ia32, and in runtime throw error:
No native build was found for platform=win32 arch=ia32...

i try to prebuild, but throw error:

Traceback (most recent call last):
  File "C:\Users\10121\AppData\Roaming\nvm\v16.13.0\node_modules\node-gyp\gyp\gyp_main.py", line 45, in <module>
    sys.exit(gyp.script_main())
  File "C:\Users\10121\AppData\Roaming\nvm\v16.13.0\node_modules\node-gyp\gyp\pylib\gyp\__init__.py", line 686, in script_main
    return main(sys.argv[1:])
  File "C:\Users\10121\AppData\Roaming\nvm\v16.13.0\node_modules\node-gyp\gyp\pylib\gyp\__init__.py", line 678, in main
    return gyp_main(args)
  File "C:\Users\10121\AppData\Roaming\nvm\v16.13.0\node_modules\node-gyp\gyp\pylib\gyp\__init__.py", line 645, in gyp_main
    [generator, flat_list, targets, data] = Load(
  File "C:\Users\10121\AppData\Roaming\nvm\v16.13.0\node_modules\node-gyp\gyp\pylib\gyp\__init__.py", line 155, in Load
    result = gyp.input.Load(
  File "C:\Users\10121\AppData\Roaming\nvm\v16.13.0\node_modules\node-gyp\gyp\pylib\gyp\input.py", line 3002, in Load
    LoadTargetBuildFile(
  File "C:\Users\10121\AppData\Roaming\nvm\v16.13.0\node_modules\node-gyp\gyp\pylib\gyp\input.py", line 475, in LoadTargetBuildFile
    gyp.common.ResolveTarget(build_file_path, dependency, None)[0]
  File "C:\Users\10121\AppData\Roaming\nvm\v16.13.0\node_modules\node-gyp\gyp\pylib\gyp\common.py", line 87, in ResolveTarget
    [parsed_build_file, target, parsed_toolset] = ParseQualifiedTarget(target)
  File "C:\Users\10121\AppData\Roaming\nvm\v16.13.0\node_modules\node-gyp\gyp\pylib\gyp\common.py", line 62, in ParseQualifiedTarget
    target_split = target.rsplit(":", 1)
AttributeError: 'int' object has no attribute 'rsplit' while trying to load binding.gyp

then i edit common.py from target.rsplit(":", 1) to str(target).rsplit(":", 1), but then throw error:

gyp: page not found (cwd: D:\project\customNapiPkg\ref-napi) while loading dependencies of binding.gyp while trying to load binding.gyp

ant i don't know how to fix it.

can you help me

@Breush
Copy link

Breush commented Sep 21, 2023

@Breush can you prebuild for ia32 in your pkg?

No. I don't plan to maintain these projects, and plan to archive these.

rak-phillip added a commit to rak-phillip/rancher-desktop that referenced this issue Sep 29, 2023
Electron 21 enabled V8 sandboxed pointers, following Chrome's decision to do the same in Chrome 103. This has some implications for native modules, namely ArrayBuffers which point to external ("off-heap") memory are no longer allowed. This breaks our `win-ca.ts` implementation. We're opting to use these forks as a short-term fix to allow us to upgrade to the latest version of electron as we evaluate a long-term fix.

See the following links for more details:
- https://www.electronjs.org/blog/v8-memory-cage
- node-ffi-napi/node-ffi-napi#238

Signed-off-by: Phillip Rak <rak.phillip@gmail.com>
rak-phillip added a commit to rak-phillip/rancher-desktop that referenced this issue Sep 29, 2023
Electron 21 enabled V8 sandboxed pointers, following Chrome's decision to do the same in Chrome 103. This has some implications for native modules, namely ArrayBuffers which point to external ("off-heap") memory are no longer allowed. This breaks our `win-ca.ts` implementation. We're opting to use these forks as a short-term fix to allow us to upgrade to the latest version of electron as we evaluate a long-term fix.

See the following links for more details:
- https://www.electronjs.org/blog/v8-memory-cage
- node-ffi-napi/node-ffi-napi#238

Signed-off-by: Phillip Rak <rak.phillip@gmail.com>
rak-phillip added a commit to rak-phillip/rancher-desktop that referenced this issue Sep 29, 2023
Electron 21 enabled V8 sandboxed pointers, following Chrome's decision to do the same in Chrome 103. This has some implications for native modules, namely ArrayBuffers which point to external ("off-heap") memory are no longer allowed. This breaks our `win-ca.ts` implementation. We're opting to use these forks as a short-term fix to allow us to upgrade to the latest version of electron as we evaluate a long-term fix.

See the following links for more details:
- https://www.electronjs.org/blog/v8-memory-cage
- node-ffi-napi/node-ffi-napi#238

Signed-off-by: Phillip Rak <rak.phillip@gmail.com>
rak-phillip added a commit to rak-phillip/rancher-desktop that referenced this issue Sep 29, 2023
Electron 21 enabled V8 sandboxed pointers, following Chrome's decision to do the same in Chrome 103. This has some implications for native modules, namely ArrayBuffers which point to external ("off-heap") memory are no longer allowed. This breaks our `win-ca.ts` implementation. We're opting to use these forks as a short-term fix to allow us to upgrade to the latest version of electron as we evaluate a long-term fix.

See the following links for more details:
- https://www.electronjs.org/blog/v8-memory-cage
- node-ffi-napi/node-ffi-napi#238

Signed-off-by: Phillip Rak <rak.phillip@gmail.com>
@ej-toita
Copy link

Since it doesnt seem likely to me that this problem is going to be solved, I have moved onto node-addon-api.
It works very well and I recommend to try it out.

@oinochoe
Copy link

I'm going through the same thing. After upgrading from Electron version 19 to version 27,

@cclauss
Copy link

cclauss commented Nov 29, 2023

As discussed in #248 and #255 this code only works on end-of-life versions on Node.js.

@angelfraga
Copy link

Hi there, I am also facing same issue with electron upgrade and this library since its functionality is mandatory in the project I am working on.

I think it would be great someone from electron/node-ffi-napi should provide an official fork/patch adding the commented fixes and some instructions/recommendations even if gets archived in order to avoid third party forks.

So sticking to last electron compatible version 20.3.8 or trying out koffi package seem only ways for me who I am a 0 skills in C/C++ for writing my own node add-on.

In addition a personal recommendation for anyone thinking about installing any of the mentioned forks/packages:

@lwahonen/ffi-napi, @lwahonen/ref-napi or @breush/ffi-napi, @breush/ref-napi

Even if these are working and they are not malicious code, you should be aware that these projects are not 100% github forks and their integrity is not guaranteed, in other words they do not share the same history with this repo.
Maybe it is something their author could fix.

@lwahonen
Copy link

Even if these are working and they are not malicious code, you should be aware that these projects are not 100% github forks and their integrity is not guaranteed, in other words they do not share the same history with this repo. Maybe it is something their author could fix.

I don't have the time / motivation for this. Maybe @angelfraga could create the version you seek, instead of asking someone else?

@Elendiar
Copy link

Elendiar commented Dec 20, 2023

@angelfraga
I just finished migrating my electron project to koffi.
So far I have achieved 100% work in the x64 build, but in ia32 build the program crashes without any error after launch. Now I'm trying to figure this out, but I'm sure it's due to incorrect types, because i dont test functions in x86 environment.
I liked Koffi in general. Working with structures and pointers is more convenient.

@angelfraga
Copy link

@lwahonen first of all thanks for your fork. I will give a try to manage your changes in order to integrated them in a real fork (as I said I have 0 knowledge of C/C++ but never is too late to get an new skill )
If everything works as it should I will open an official MR. So everyone could follow the git history.

@Elendiar Thanks for let us know about your experience with koffi 👍 , probably next step I will do is giving a try to this, in short it seems to be the quick solution. So I will post back when trying out ia32.

@Elendiar
Copy link

@angelfraga I used @inigolabs/ref-napi fork when electron updates with context isolation, it works but when i recently want update project (electron taskbar client for production computers, which register self as system taskar with registerWindowMessageA and shAppBarMessage, also register wineventHook etc), i cant build it due node-gyp error.

I managed to rewrite all these functions in koffi, but now I need to try to execute them on x86 OS, or by commenting codeblocks and assembling to understand where the problem is. At least the module that is responsible for registering the taskbar in the system works in x86 fine.

@eyalewin
Copy link

I've eneded up replacing ffi-napi to koffi
Then had to change mainWindow
mainWindow = new BrowserWindow({ ... webPreferences: { nodeIntegration: true, }, });

and i was finally able to upgrade electron from 19.x to 20.x

@s0hanian
Copy link

Adding another recommendation for https://github.com/Koromix/koffi
I switched to that without too much of an issue with only academic C++ experience. My app is now running Electron v28.

@angelfraga
Copy link

angelfraga commented Jan 2, 2024

Hi there again , happy new year. First, thanks everyone for the feedback about Koffi.

As my last words about that topic.

As a team mate found out, here node-ffi-napi/ref-napi#64 looks like the right fix for ArrayBuffers which might be also the fix for Electron 20.3.9 issue https://www.electronjs.org/de/blog/v8-memory-cage

I am wondering because that PR seems to pass all tests and it was already reviewed (like other PR in these two repos which are also not merged yet).
But #247 it looks like abandoned repo.

So if you need to avoid new dependencies, I would recommend to give a try and check that branch from the PR since its history is aligned with the main branch. You might need to build in it your target arch.

If you do not have these limitations, based on the other users comments https://github.com/Koromix/koffi seems to be the next step.

@Venryx
Copy link

Venryx commented Feb 15, 2024

Adding another recommendation for Koffi. It's been working well for me so far in the latest version of Electron, and it has pretty extensive documentation: https://koffi.dev

(Before trying koffi I had tried using the @breush/ref-napi fork, which @stevenlafl got working on a newer electron version, however when I tried it I hit the same error that @ej-toita hit here.)

But yeah; it's biggest benefit at the moment is simply that it's not abandoned, and has good documentation.

Like @Elendiar mentioned, I also like its handling of structures and pointers -- I found it easier to figure out how to implement them properly. (due partly just to its documentation I guess)

An example usage of koffi from my rewrite:

export const Rect = koffi.struct("Rect", {left: "ulong", top: "ulong", right: "ulong", bottom: "ulong"});
export const LPRect = koffi.pointer("LPRect", "Rect");
// Leaving out the HWND def, since I'm a rebel and define it as `int64` for easier usage, rather than a proper pointer-type. How bad is this? XD

const lib = koffi.load("user32.dll");
export const user32 = {
	GetWindowRect: lib.func("bool GetWindowRect(HWND hWnd, _Out_ LPRect lpRect)"),
	//GetWindowRect: lib.func("GetWindowRect", "bool", [HWND, koffi.out(LPRect)]), // alternative syntax
};

export type RectShape = {left: number, top: number, right: number, bottom: number};
export function getWindowRect(handle) {
	const rect = {} as RectShape;
	var success = user32.GetWindowRect(handle, rect);
	if (!success) return null;

	return rect;
}

While the node-ffi equivalent is about the same amount of code, I think the koffi API is a little more intuitive. (eg. not split into multiple libraries like ffi-napi + ref-napi + ref-struct-di, more standard name with koffi.pointer instead of ref.refType, and being able to pass in the rect structure itself as an argument rather than rect.ref())

@xjh1230
Copy link

xjh1230 commented Mar 28, 2024

@Breush can you prebuild for ia32 in your pkg? i can use your pkg in dev. but myapp is build ia32, and in runtime throw error: No native build was found for platform=win32 arch=ia32...

i try to prebuild, but throw error:

Traceback (most recent call last):
  File "C:\Users\10121\AppData\Roaming\nvm\v16.13.0\node_modules\node-gyp\gyp\gyp_main.py", line 45, in <module>
    sys.exit(gyp.script_main())
  File "C:\Users\10121\AppData\Roaming\nvm\v16.13.0\node_modules\node-gyp\gyp\pylib\gyp\__init__.py", line 686, in script_main
    return main(sys.argv[1:])
  File "C:\Users\10121\AppData\Roaming\nvm\v16.13.0\node_modules\node-gyp\gyp\pylib\gyp\__init__.py", line 678, in main
    return gyp_main(args)
  File "C:\Users\10121\AppData\Roaming\nvm\v16.13.0\node_modules\node-gyp\gyp\pylib\gyp\__init__.py", line 645, in gyp_main
    [generator, flat_list, targets, data] = Load(
  File "C:\Users\10121\AppData\Roaming\nvm\v16.13.0\node_modules\node-gyp\gyp\pylib\gyp\__init__.py", line 155, in Load
    result = gyp.input.Load(
  File "C:\Users\10121\AppData\Roaming\nvm\v16.13.0\node_modules\node-gyp\gyp\pylib\gyp\input.py", line 3002, in Load
    LoadTargetBuildFile(
  File "C:\Users\10121\AppData\Roaming\nvm\v16.13.0\node_modules\node-gyp\gyp\pylib\gyp\input.py", line 475, in LoadTargetBuildFile
    gyp.common.ResolveTarget(build_file_path, dependency, None)[0]
  File "C:\Users\10121\AppData\Roaming\nvm\v16.13.0\node_modules\node-gyp\gyp\pylib\gyp\common.py", line 87, in ResolveTarget
    [parsed_build_file, target, parsed_toolset] = ParseQualifiedTarget(target)
  File "C:\Users\10121\AppData\Roaming\nvm\v16.13.0\node_modules\node-gyp\gyp\pylib\gyp\common.py", line 62, in ParseQualifiedTarget
    target_split = target.rsplit(":", 1)
AttributeError: 'int' object has no attribute 'rsplit' while trying to load binding.gyp

then i edit common.py from target.rsplit(":", 1) to str(target).rsplit(":", 1), but then throw error:

gyp: page not found (cwd: D:\project\customNapiPkg\ref-napi) while loading dependencies of binding.gyp while trying to load binding.gyp

ant i don't know how to fix it.

can you help me

gyp: page not found Have you solved your problem?

@cclauss
Copy link

cclauss commented Mar 28, 2024

@xjh1230 In your error log, please find the line that contains gyp info using node-gyp@

I sense you are running an old version of node-gyp.

@xjh1230
Copy link

xjh1230 commented Mar 29, 2024

@xjh1230 In your error log, please find the line that contains gyp info using node-gyp@

I sense you are running an old version of node-gyp.

node -v v16.5.0 & node-gyp -v v9.0.0
node -v v14.21.3 & node-gyp -v v5.1.1
node -v v20.11.1 & node-gyp -v v10.0.1

@cclauss
Copy link

cclauss commented Mar 29, 2024

For my node-ffi-napi recommendations, please see

As mentioned above, you will probably have more success with this fork https://github.com/lwahonen/node-ffi-napi

@xjh1230
Copy link

xjh1230 commented Apr 1, 2024

For my node-ffi-napi recommendations, please see

As mentioned above, you will probably have more success with this fork https://github.com/lwahonen/node-ffi-napi

error:

npm ERR! gyp: node-addon-api\node_api.gyp not found  (cwd: D:\code\node-ffi-napi-main\node_modules\@lwahonen\ref-napi) while loading dependencies of binding.gyp while trying to load binding.gyp

@GMYXDS
Copy link

GMYXDS commented May 6, 2024

electron 版本切换到 20.0.0
然后npm install 2次可以正常运行

The electron version is switched to 20.0.0
Then npm install 2 times can run normally
It's worked for me

@GMYXDS
Copy link

GMYXDS commented May 6, 2024

@GMYXDS Are you on Linux, macOS, or Windows?

now for windwos.further maybe macoos
node: v20.11.1
electron base on electron-vite:https://cn-evite.netlify.app/
@cclauss

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

No branches or pull requests