TechStark / opencv-js

OpenCV JavaScript version for node.js or browser
Apache License 2.0
353 stars 31 forks source link

[node.js] Error thrown at opencv.js:30 with all the module code printed out to the console #31

Open toniopelo opened 12 months ago

toniopelo commented 12 months ago

While using this package on node, I would have errors thrown in what appeared to be a "random" fashion, without any concrete explanations in the error. It would just output the whole opencv.js module minified code and fail.

This kind of errors while using opencv.js followed me for a while before I took the time to go into a deep investigation of the root cause. I will post as a comment below my explanation and what worked for me for others in my situation.

toniopelo commented 12 months ago

Explanation:

This is what cause these apparently random errors with no details. The original error probably comes from elsewhere in your codebase, but this is handled here by this emscripten wrapper and re-thrown without details.

Solution: After several hours of rebuilding the opencv.js module with a newer version of emscripten, tweaking the build arguments and so on, I gave up this approach because it failed at runtime for reasons I choose to not investigate due to time constraints (even though I managed to produce several other versions of opencv.js that didn't contain the process.on() calls). I finally ended up by just using my own version of the opencv.js module and removing the process.on() calls from it. I used the same version that this package use, but I don't use this package anymore so I can remove these faulty lines from it. I used mirada as it is done here to have the typescript definitions. I finally added a process.on('uncaughtException', () => {...}) elsewhere in my codebase to handle properly these errors woth proper logs and all.

I'll keep this issue open as the package is still having this issue and my solution is more a workaround.