Building WASM Opencv.js: 'cv' is a Promise, not an Object

I am currently successfully using OpenCV.js from a web worker. The procedure I have been using so far is importScripts(“https://docs.opencv.org/4.9.0/opencv.js”). This works just fine.

More recently, I built OpenCV.js using emscripten, from a Linux (WSL) environment.

If I issue:

emcmake python3 ./opencv/platforms/js/build_js.py build_wasm --build_wasm

this creates 3 files:

build_wasm/bin/loader.js
build_wasm/bin/opencv.js
build_wasm/bin/opencv_js.js

Now, if I import opencv.js instead of https://docs.opencv.org/4.9.0/opencv.js in my code, things are not working as expected.

Specifically, ‘cv’ is a Promise when I build OpenCV myself, and is an Object when I use the above URL.

When ‘cv’ is an Object, my OpenCV initialization procedure works fine:

// This code cannot work if 'cv' is a Promise
if (cv.getBuildInformation)
{
    console.log(cv.getBuildInformation());
    onloadCallback();
}
else
{
    // WASM
    cv['onRuntimeInitialized']=()=>{
        console.log(cv.getBuildInformation());
        onloadCallback();
    }
}

However it does not work when I build OpenCV myself.
Is there anything additional I should do after issuing the above build command?

Thanks for your help.

EDIT: I can do ‘cv = await cv;’ after importScripts, but this seems very hacky.