santigimeno / node-pcsclite

Bindings over pcsclite to access Smart Cards
ISC License
170 stars 127 forks source link

Electron: Loading non-context-aware native module in renderer #95

Open alba-ado opened 2 years ago

alba-ado commented 2 years ago

Hello, thank you very much for this library. I have been running this library with electron for quite some time now. However, as I decided to update my version of the electron, I found that it gives an error because of the N-API compatibility (I think). In the earlier versions of the electron, it was possible to turn this off by using

app.allowRendererProcessReuse = false;

However, they have removed this approach in the latest versions of the electron. How can we fix this problem? Or can you issue an update regarding the fix of context-aware modules?

Here is the full error message I'm getting:

Uncaught Error: Loading non-context-aware native module in renderer: '/home/ado/Projects/Electron/node_modules/@pokusew/pcsclite/build/Release/pcsclite.node

at process.func [as dlopen] (node:electron/js2c/asar_bundle:5) at Object.Module._extensions..node (node:internal/modules/cjs/loader:1199) at Object.func [as .node] (node:electron/js2c/asar_bundle:5) at Module.load (node:internal/modules/cjs/loader:988) at Module._load (node:internal/modules/cjs/loader:829) at Function.c._load (node:electron/js2c/asar_bundle:5) at Function.o._load (node:electron/js2c/renderer_init:33) at Module.require (node:internal/modules/cjs/loader:1012) at require (node:internal/modules/cjs/helpers:94) at bindings (/home/ado/Projects/Electron/node_modules/bindings/bindings.js:112)

This problem is probably caused by using an old version of the bindings module. Is there any possibility that this could be fixed?

Thank you very much in advance

alba-ado commented 2 years ago

Sidenote: Here is an issue on the electron page for this problem with other libraries, but they insist that it is the problem of the library repos to fix this; https://github.com/electron/electron/issues/18397

aigeth19 commented 2 years ago

I am dealing with the same problem, have you found any solutions?

santigimeno commented 2 years ago

Can you test if https://github.com/santigimeno/node-pcsclite/pull/96 fixes the issue? Completely untested patch

aigeth19 commented 2 years ago

Thanks, that seems to fix it.

alba-ado commented 2 years ago

Hello, I couldn't try the #96 because I'm using another library "nfc-pcsc" because it uses this library as a dependency and I couldn't manage to successfully change it. I know it is a bit risky, but can you merge and push this version into npm repository so we can use it? It doesn't seem like you've changed much. I think it should work just fine.

aigeth19 commented 2 years ago

I was using it in a similar way as a dependency. You could try put the code in manually inside /pcsclite/src/addon.cpp and rebuilding nfc-pcsc.

alba-ado commented 2 years ago

Oh, thank you! I didn't test very deeply but I can also confirm that #96 is working with the latest version of electron (16.0.4). Would be great if you could publish it in the npm though.

bastianandre commented 2 years ago

I can confirm that #96 works with Electron 17.1.0. Would be great, if this would be implemented!