Switching to NAN_MODULE_WORKER_ENABLED broke my native node module
To make my module work in the latest version of Electron I had to change from:
void Init(v8::Local<v8::Object> exports)
{
CoInitialize(nullptr);
NAN_EXPORT(exports, createShortcut);
}
NODE_MODULE(example1, Init)
To this:
NAN_MODULE_INIT(Init)
{
CoInitialize(nullptr);
Nan::SetMethod(target, "createShortcut", createShortcut);
}
NAN_MODULE_WORKER_ENABLED(example1, Init)
This is how I am building the module:
node-gyp rebuild --target=17.1.2 --arch=x64 --dist-url=https://electronjs.org/headers
And these are the dependencies I'm using:
"devDependencies": {
"electron": "^17.1.2",
"electron-builder": "^22.4.1",
"nan": "^2.15.0",
"node-gyp": "^6.1.0"
},
Everything builds just fine but now I get the following error when trying to load the module:
VM280 renderer_init:formatted:740 Error: Module did not self-register: '\?\C:\Projects\TeamsOS_AppLauncher\build\Debug\example1.node'. at process.func [as dlopen] (VM277 asar_bundle:5:1800) at Object.Module._extensions..node (VM261 loader:1199:18) at Object.func [as .node] (VM277 asar_bundle:5:1800) at Module.load (VM261 loader:988:32) at Module._load (VM261 loader:829:12) at Function.c._load (VM277 asar_bundle:5:13331) at Function.o._load (VM280 renderer_init:formatted:368:31) at Module.require (VM261 loader:1012:19) at require (VM260 helpers:102:18) at Object.
(VM282 C:\Projects\TeamsOS_AppLauncher\preload.js:2:18)
Please help! What am I doing wrong? I've been banging my head into this all evening.
Hello , look code . There is no error after writing this way
// 声明模块名称
NODE_MODULE(addon, Init)
NAN_MODULE_WORKER_ENABLED(addon, Init)