I've also faced this problem and solved the problem by using --disable_wasm option, e.g., python ./platforms/js/build_js.py build_js --disable_wasm, which ends up building an asm.js version of opencv.js. Then const cv = require('./opencv.js'); will block until the opencv.js will is fully loaded.
Note that asm.js version of opencv.js is slower than that of wasm, but it was more important for me to make the import step easy for me for teaching purposes.
Thank you for sharing useful info!
I've also faced this problem and solved the problem by using
--disable_wasm
option, e.g.,python ./platforms/js/build_js.py build_js --disable_wasm
, which ends up building anasm.js
version of opencv.js. Thenconst cv = require('./opencv.js');
will block until the opencv.js will is fully loaded.Note that asm.js version of opencv.js is slower than that of wasm, but it was more important for me to make the import step easy for me for teaching purposes.
For details see npmjs.com/package/@mjyc/opencv.js.