K
K
Kirill Novak2019-03-03 13:47:20
JavaScript
Kirill Novak, 2019-03-03 13:47:20

Why does it write an error Error: Module did not self-register when working with worker threads (canvas)?

The error appears only if I request the canvas module in the child Worker.
I tried to do a reinstall of the modules, deleted the node_modules folder, did a rebuild.
All this did not help
Nodejs latest version, npm too

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Proskurin, 2019-03-03
@Vlad_IT

oh, how much I suffered with this garbage in the electron ...
You can’t do anything especially, because node modules do not work in multithreading. Even if you manage to import the module, the node will crash with an asynchronous callback. I managed to import, but the module can only be imported in one thread (the main thread is also considered). those. if you imported the module in the main thread of the application, or in another worker, you will not be able to import it again. Of course, you can create a separate compiled file for each worker, but this is a crutch.

L
lostero, 2020-07-05
@lostero

The only solution is to fork and edit the binding for multithreading.
For more than 3 years, developers have been closing such issues as impossible.
This is a jamb of native module developers.
Module data must be bound to the context in which it is created (NodeJS Context-aware addon)
And must be cleared when the context is destroyed, via special. Node Hook
The developers of this addon either don't know about it, or slaughter it in favor of supporting older versions of the node.
worker_thread, child_process use their own Node instances for each thread.
If the native module can't use it, then it's the native module developer's problem.
I'm not in the tooth with my foot in the C / C ++ syntax, but I was able to make the native library for encoding images in h264 work as it should in node streams (8-50 microseconds per 1080p frame).
My patience to rewrite the binding after others is also not enough for this module, I’ll clone the module or throw data from a separate process (if it’s completely poor in terms of performance, I have to climb into C / C ++ and crookedly code the module with crooked hands to make it more productive, because guru C/C++ rarely gets into open source without sponsors).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question