TechStark / opencv-js

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

Cannot assign to 'onRuntimeInitialized' because it is a read-only property. #47

Closed chalapathi444 closed 5 months ago

chalapathi444 commented 7 months ago

onRuntimeInitialized is a read-only property., Not able to assign a function to it. Is there any way to know if the cv is initialized?

await new Promise<void>( 
      (resolve) =>
        (cv['onRuntimeInitialized'] = () => {
          resolve();
        });
    );
Npscholar commented 7 months ago

Hey @chalapathi444 haven't dug deep into this but have you checked this closed issue? Seems close to what you are asking #33

ttt43ttt commented 7 months ago

@chalapathi444 do you see the error when compiling TypeScript to JavaScript or running JavaScript code? It should work. See https://github.com/TechStark/opencv-js/blob/main/test/cv.ts#L6

davidjandrey-sv commented 7 months ago

I get the same error when parcel tries to transpile & optimize my code:

@parcel/optimizer-swc: cannot reassign to an imported binding

Also VSCode itself is warning me beforehand:

image image

ttt43ttt commented 7 months ago

@davidjandrey-sv which version are you using? could you provide the code/demo page to show the issue?

davidjandrey-sv commented 7 months ago

@ttt43ttt I'm using it for my npm package: https://www.npmjs.com/package/intellicrop I've reproduced this issue with 4.8.0-release.4 and 4.8.0-release.10. I can try to set up a demo page for you later on, but you can see the issue if you check out my package and just try to assign a new value to the onRuntimeInitialized prop anywhere.

ttt43ttt commented 7 months ago

@davidjandrey-sv I've checked your package. Here is a way that can make it work.

davidjandrey-sv commented 7 months ago

@ttt43ttt Yup, that worked flawless for me, thank you very much and have a nice weekend :)