node-xxhash icon indicating copy to clipboard operation
node-xxhash copied to clipboard

Uncaught Error: Module did not self-register

Open Somebi opened this issue 6 years ago • 5 comments

Getting this error... removing node_modules or npm rebuild is not helping. This error is thrown when i'm using threads (workers)

Somebi avatar Mar 01 '19 13:03 Somebi

Node version?

mscdex avatar Mar 01 '19 15:03 mscdex

node addons have to explicitly support workers for them to work in that scenario. The main reason for this is that some addons can have global state which would not work for multiple threads.

mscdex avatar Mar 01 '19 15:03 mscdex

V10.10 don't remember for sure.

пт, 1 мар. 2019 г., 17:27 mscdex [email protected]:

node addons have to explicitly support workers for them to work in that scenario. The main reason for this is that some addons can have global state which would not work for multiple threads.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/mscdex/node-xxhash/issues/26#issuecomment-468702579, or mute the thread https://github.com/notifications/unsubscribe-auth/AAc7oaI6KkJryXwxystvT-bulHkHbMdmks5vSUbbgaJpZM4bZDHs .

Somebi avatar Mar 03 '19 08:03 Somebi

But calling require not in the global scope, works without errors. Problem exists only when define module in the top most place (i.e. global scope)

вс, 3 мар. 2019 г., 10:13 Denis Abramov [email protected]:

V10.10 don't remember for sure.

пт, 1 мар. 2019 г., 17:27 mscdex [email protected]:

node addons have to explicitly support workers for them to work in that scenario. The main reason for this is that some addons can have global state which would not work for multiple threads.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/mscdex/node-xxhash/issues/26#issuecomment-468702579, or mute the thread https://github.com/notifications/unsubscribe-auth/AAc7oaI6KkJryXwxystvT-bulHkHbMdmks5vSUbbgaJpZM4bZDHs .

Somebi avatar Mar 03 '19 08:03 Somebi

Can you show an example of each?

mscdex avatar Mar 03 '19 08:03 mscdex

I have meet same issue when tried to require xxhash in thread (node v12.8.1, pull/30 applied). But was able to solve it by changing src/hash.cc:

11c11,13
< NODE_MODULE(addon, Init);
---
> NODE_MODULE_INIT() {
>   Init(exports);
> }

and re-build binary: cd build && make

Code to reproduce the issue:

(async () => {
  const { job, start, stop } = require('microjob');
  var XXHash = require('xxhash')
  await start();
  await job(() => {
      var XXHash = require('xxhash')
  })
})()

migolovanov avatar Aug 22 '19 11:08 migolovanov