Can't use native node addon with nw.js (FACILITY_VISUALCPP/ERROR_PROC_NOT_FOUND)

161 views
Skip to first unread message

Ashley Gullen

unread,
Sep 13, 2023, 11:49:31 AM9/13/23
to nw.js
Hi folks,

I'm trying to build a node native addon specifically for use with NW.js. I'm really struggling. It's difficult to find any clear guides that cover this end-to-end with the latest recommended APIs for ABI compatibility. I've managed to get a test node native addon that builds and works in node.js. I've taken care to match versions for ABI compatibility and follow the NW.js specific instructions under "Use Native Node Modules" in the NW.js documentation. However when I actually run it in NW.js, the call to require() that loads the native addon crashes the tab with error code FACILITY_VISUALCPP/ERROR_PROC_NOT_FOUND.

I'm on Windows 11 x64 with Visual Studio 2022. The build commands I used are in 'build cmds.txt'. I installed node.js 20.5.1 and extracted NW.js 0.79.1 to the nwjs-test folder to test running it. When you click the test button the tab crashes. The debugger also closes and so I have no idea what happened or what I could do about it. It works correctly when run in node - running `node index.js` in the node-native-addon folder logs the correct messages. It's only NW.js that fails to load it.

All I need is a native node addon that can receive a string from JavaScript, and later fire a JavaScript message event with a string parameter, and then I can do the rest myself. But I can't figure out how to get even a small native node addon to successfully load in NW.js. Even just a simple hello world sample that works in NW.js using Node-API for ABI stability would be a big help as it would at least provide a working starting point. Any help getting this working would be very much appreciated!

Best regards

Ashley Gullen
Scirra Ltd

Roger Wang

unread,
Sep 13, 2023, 11:54:32 AM9/13/23
to Ashley Gullen, nw.js
There is a test case 'native-module-buffer' in the repo, https://github.com/nwjs/nw.js/tree/nw79/test/sanity/native-module-buffer

It compiles and tests a simple native addon.

Regards,
Roger

--
You received this message because you are subscribed to the Google Groups "nw.js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nwjs-general...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nwjs-general/CAABs73hO%3DqvReTAeH3LaJxLU_MHg8cu%3DZ9zMAqsx3V-7TZr%2BKA%40mail.gmail.com.

Ashley Gullen

unread,
Sep 13, 2023, 12:00:59 PM9/13/23
to Roger Wang, nw.js
Thanks, I had a look, but it looks like it uses NAN, whereas the latest API seems to be Node-API which is the one I was trying to use. ABI stability across versions would be extremely useful - having to rebuild stuff for every release is a real pain. Is there a Node-API example that works with NW.js? Or is it just not supported?

Ashley

Roger Wang

unread,
Sep 13, 2023, 12:09:53 PM9/13/23
to Ashley Gullen, nw.js
Unfortunately there is no API/ABI compatibility across versions...

Ashley Gullen

unread,
Sep 15, 2023, 7:12:34 AM9/15/23
to Roger Wang, nw.js
Too bad about the ABI, I guess we can figure out how to live with it.

However I tried building the 'native-module-buffer' test and it has compile errors for me. Is it out of date?

---

...\nan-test\native-addon\node_modules\nan\nan.h(688,37): warning C4996: 'v8::Isolate::IdleNoti
ficationDeadline': Use MemoryPressureNotification() to influence the GC schedule. [...\nan-test
\native-addon\build\buffer_example.vcxproj]
...\nan-test\native-addon\buffer_example.cpp(11,54): error C2660: 'v8::Value::ToObject': functi
on does not take 0 arguments [...\nan-test\native-addon\build\buffer_example.vcxproj]
C:\Users\ashle\AppData\Local\node-gyp\Cache\20.5.1\include\node\v8-value.h(382,44): message : see declaration of 'v8::V
alue::ToObject' [...\nan-test\native-addon\build\buffer_example.vcxproj]
...\nan-test\native-addon\buffer_example.cpp(11,54): message : while trying to match the argume
nt list '()' [...\nan-test\native-addon\build\buffer_example.vcxproj]
...\nan-test\native-addon\buffer_example.cpp(13,31): error C2660: 'v8::Value::Uint32Value': fun
ction does not take 0 arguments [...\nan-test\native-addon\build\buffer_example.vcxproj]
C:\Users\ashle\AppData\Local\node-gyp\Cache\20.5.1\include\node\v8-value.h(426,41): message : see declaration of 'v8::V
alue::Uint32Value' [...\nan-test\native-addon\build\buffer_example.vcxproj]
...\nan-test\native-addon\buffer_example.cpp(13,31): message : while trying to match the argume
nt list '()' [...\nan-test\native-addon\build\buffer_example.vcxproj]
...\nan-test\native-addon\buffer_example.cpp(13,22): error C2440: 'initializing': cannot conver
t from 'v8::Maybe<uint32_t>' to 'unsigned int' [...\nan-test\native-addon\build\buffer_example.
vcxproj]
...\nan-test\native-addon\buffer_example.cpp(13,22): message : No user-defined-conversion opera
tor available that can perform this conversion, or the operator cannot be called [...\nan-test\
native-addon\build\buffer_example.vcxproj]
gyp ERR! build error

Ashley Gullen

unread,
Sep 15, 2023, 7:39:06 AM9/15/23
to Roger Wang, nw.js
I also tried another minimal example using NAN and ran `nw-gyp rebuild --target=0.79.1 --arch=x64`, but it fails:

gyp ERR! find VS running in VS Command Prompt, installation path is:
gyp ERR! find VS "C:\Program Files\Microsoft Visual Studio\2022\Community"
gyp ERR! find VS - will only use this version
gyp ERR! find VS checking VS2022 (17.7.34024.191) found at:
gyp ERR! find VS "C:\Program Files\Microsoft Visual Studio\2022\Community"
gyp ERR! find VS - found "Visual Studio C++ core features"
gyp ERR! find VS - found VC++ toolset: v143
gyp ERR! find VS - missing any Windows SDK
gyp ERR! find VS could not find a version of Visual Studio 2017 or newer to use
...
gyp ERR! UNCAUGHT EXCEPTION
gyp ERR! stack TypeError: Cannot read properties of undefined (reading 'versionYear')
gyp ERR! stack     at createConfigFile (C:\Users\ashle\AppData\Roaming\npm\node_modules\nw-gyp\lib\configure.js:175:57)
gyp ERR! stack     at C:\Users\ashle\AppData\Roaming\npm\node_modules\nw-gyp\lib\configure.js:99:13
gyp ERR! stack     at process.processTicksAndRejections (node:internal/process/task_queues:77:11)

It says "missing any Windows SDK", but I do have the Windows SDK installed at C:\Program Files (x86)\Windows Kits\10.

It also looks like nw-gyp doesn't know about Visual Studio 2022: https://github.com/nwjs/nw-gyp/blob/node-gyp-3.6.2/lib/configure.js#L95
Is it not supported, or perhaps nw-gyp is out of date?

I'd really appreciate any working example - so far I've been unable to get even a "hello world" native node addon working in NW.js.

Ashley



Ashley Gullen

unread,
Sep 18, 2023, 8:13:32 AM9/18/23
to Roger Wang, nw.js
Maybe I'm running in to this bug in nw-gyp - the Windows 11 SDK isn't recognized: https://github.com/nwjs/nw-gyp/issues/158

I suspect possibly nw-gyp doesn't support Visual Studio 2022.

Could someone from the NW.js team use up-to-date VS2022 and Windows 11 SDK and verify a simple native node addon can be built and used with NW.js? I think the build config problems are what's blocking me here.

Thanks,

Ashley


Ayush C.

unread,
Oct 18, 2023, 12:49:44 AM10/18/23
to nw.js
I was able to build Node Native addon for NW.js using node-gyp. I have only tried on Linux but it should work on MacOS and Windows. The process is quite manual and I'm trying to automate it in nw-builder (https://github.com/nwutils/nw-builder/pull/964). Here are the steps (assuming you have the node addon source code setup):

1. Install node-gyp in your Node/NW.js project.
2. Download the relevant node headers. For example, https://dl.nwjs.io/v0.80.0/nw-headers-v0.80.0.tar.gz for v0.80.0
3. Unzip the TGZ file.
4. Pass the headers directory to node-gyp via the --nodedir flag.
5. Configure and build.

I was able to verify it worked for me by building the Hello world example from the node docs (https://nodejs.org/api/addons.html#hello-world).

I encountered an issue with Python on Linux and patched the relevant file:
https://github.com/nwutils/nw-builder/pull/964/commits/88890425966518176da75438c4d19e59a65bfb6f

You might have similar issues on MacOS or Windows. Good luck!

russell....@gmail.com

unread,
Oct 18, 2023, 1:13:38 PM10/18/23
to nw.js
I've had good luck using projects that use ffi and napi so it is a little more stable across node versions. I had used node-ffi-napi on all desktop oses for a while, but node-ffi-napi has since been stopped being maintained. 

http://koffi.dev might be an alternative. But there are others like https://github.com/zhangyuang/node-ffi-rs

I have not needed to switch from node-ffi-napi but will probably need to in the near future, however the move should be pretty simple since the goal is a ffi interface.

Reply all
Reply to author
Forward
0 new messages