mmmagic icon indicating copy to clipboard operation
mmmagic copied to clipboard

Module did not self-register

Open xobotyi opened this issue 3 years ago • 6 comments

When trying to use mmagic within worker threads im receivenig below error:

Module did not self-register: '****\node_modules\mmmagic\build\Release\magic.node'.
node:internal/modules/cjs/loader:1183
  return process.dlopen(module, path.toNamespacedPath(filename));
                 ^

Error: Module did not self-register: '****\node_modules\mmmagic\build\Release\magic.node'.
    at Object.Module._extensions..node (node:internal/modules/cjs/loader:1183:18)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (****\node_modules\mmmagic\lib\index.js:1:13)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at require.extensions.<computed> (****\node_modules\ts-node\src\index.ts:1361:43)
    at Object.require.extensions.<computed> [as .js] 

node: v16.13.2 os: Windows 11

While being used within main thread - everything works just fine.

xobotyi avatar Mar 16 '22 11:03 xobotyi

I've managed to workaround and it is simply exclusion of mmm.Magic instance from thread, but it seems not the best solution.

xobotyi avatar Mar 16 '22 11:03 xobotyi

mmmagic is not compatible with workers at the moment.

mscdex avatar Mar 16 '22 14:03 mscdex

@mscdex I've also got a case where I need to use mmmagic from a worker thread. It looks like the first step towards unblocking that would be migrating from nan to node-api. I believe this would also change the minimum node version to at least 8.6.0 since that was when node-api was introduced.

Would there be any interest in a PR for that or would it be too drastic of a change?

kj800x avatar Jun 04 '22 20:06 kj800x

I'm not comfortable using node-api yet. AFAIK nan has a way to mark a module as worker-friendly, but of course that requires some code changes because you need to make sure that (per-worker/isolate/whatever) resources are properly cleaned up whereas currently there are some globals used.

mscdex avatar Jun 04 '22 20:06 mscdex

I've managed to workaround and it is simply exclusion of mmm.Magic instance from thread, but it seems not the best solution.

Hi @xobotyi, could you please elaborate a bit on this workaround? How did you exclude the package from the worker thread?

tnabil avatar Mar 09 '23 01:03 tnabil

@tnabil just rethinked the flow and been able to use mmmagic in main thread

xobotyi avatar Mar 22 '23 11:03 xobotyi