Uncaught Error: Module did not self-register
With the actual version 24.4 of nw.js i am encountering the following error on reload.
Uncaught Error: Module did not self-register.
at Object.Module._extensions..node (module.js:644:18)
at Module.load (module.js:531:32)
at tryModuleLoad (module.js:494:12)
at Function.Module._load (module.js:486:3)
at Module.require (module.js:541:17)
at require (internal/module.js:11:18)
at Object.
Hm, nw-dev probably doesn't work with native modules at all right now. My understanding is that the module is probably not being unloaded ("deregistered", if that's a thing?), so it doesn't try to reregister itself when required a second time. To refresh modules, nw-dev simply and naively clears out the require cache.
But since this is a third party library, you might not need or want it to be unloaded and reloaded, so it might work to simply have a filter to exclude the module from being cleared out of the require cache.
(You might also need to clean up database connections in onbeforeunload or onunload.
I guess it won't be able to be synchronous, but hopefully that's fine.)
Tomorrow I'll try to reproduce this and see about adding a cache busting exclusion filter option.
Can You tell me how to exclude sqlite3? I thought node_modules are ignored by default. Thx for helping. If you have trouble installing sqlite3. The correct command for mac is.
npm install sqlite3 --build-from-source --runtime=node-webkit --target_arch=x64 --target="0.24.4" --save
There's no option for it yet; the ignore filter only affects what is watched, to determine whether to reload, not what to reload. Modules are purged from the cache regardless so that modules that have internal state will start fresh on a reload. (For example if there was a module with a function that returns numbers sequentially starting at 1, you might want its output to be deterministic, not for it to get higher by however many times you got an ID on every reload.)
But as a workaround, you could probably manually avoid requiring it multiple times with a global variable:
global.sqlite = global.sqlite || require("sqlite3");
npm got node_modules into a broken state, missing npmlog (a dependency of node-pre-gyp), but after deleting node_modules a couple times and reinstalling it worked again, and I was able to reproduce the error.
Since it works fine when reloading from the devtools with Ctrl+R, I wonder if there's something I could into to reload in that way, to replace invalidating the cache.
I meant to post this earlier:
On second thought, it works fine because of not clearing the cache, but clearing the cache is still desirable for other modules, especially user code.
So the Window methods reload, reloadIgnoringCache, and reloadDev wouldn't help with that,
although would probably be good to use anyways.
There is apparently chrome.runtime.restart() too but it probably still wouldn't be able to unload native node modules.
Issue in node: https://github.com/nodejs/node/issues/6160