Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught Error: Module did not self-register #4

Open
Silve2611 opened this issue Sep 4, 2017 · 5 comments
Open

Uncaught Error: Module did not self-register #4

Silve2611 opened this issue Sep 4, 2017 · 5 comments

Comments

@Silve2611
Copy link

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. (/Users/timebro/timeBro/git/mac/front/timeBro.app/Contents/Resources/app.nw/node_modules/sqlite3/lib/sqlite3.js:4:15)
at Module._compile (module.js:597:30)
at Object.Module._extensions..js (module.js:614:10)
at Module.load (module.js:531:32)

@1j01
Copy link
Collaborator

1j01 commented Sep 5, 2017

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.

@Silve2611
Copy link
Author

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

@1j01
Copy link
Collaborator

1j01 commented Sep 5, 2017

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");

@1j01
Copy link
Collaborator

1j01 commented Sep 6, 2017

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.

@1j01
Copy link
Collaborator

1j01 commented Nov 7, 2017

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: nodejs/node#6160

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants