Switching to NAN_MODULE_WORKER_ENABLED broke my native node module
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 3.4k
- Forks
- 531
- Avg merge
- 21m
- Merged PRs (30d)
- 1
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the NAN_MODULE_INIT and NAN_MODULE_WORKER_ENABLED snippets, then reproduce the node-gyp rebuild using Electron 17.1.2 headers. Check why the resulting example1.node fails to self-register when required from preload.js. Done means the native module builds and loads without the reported self-register error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- electron, node.js
- Domain
- backend, build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100