TechStark / opencv-js

OpenCV JavaScript version for node.js or browser
https://npmjs.com/@techstark/opencv-js
Apache License 2.0
408 stars 36 forks source link

Module is not defined errors after upgrading to 4.8.0 #33

Closed skmbr closed 1 year ago

skmbr commented 1 year ago

I've been working on a project using this package in a Vue.js / Quasar app and everything was working fine until I upgraded it today.

A simplified version of my implementation looks like this:

<template>
  <div v-if="openCvReady">
    <img src="/myImg.jpg" ref="myImg" @click="testImage" />
    <canvas id="canvasOutput" />
  </div>
</template>

<script>

import cv from '@techstark/opencv-js'

export default {

  data () {
    return {
      openCvReady: false
    }
  },

  methods: {
    testImage () {
      const img = cv.imread(this.$refs.myImg)
      cv.imshow('canvasOutput', img)
    }
  },

  mounted () {
    cv.onRuntimeInitialized = () => {
      console.log('OpenCV.js is ready')
      this.openCvReady = true
    }
  }
}
</script>

But this results in errors like this:

opencv.js:46 Uncaught (in promise) ReferenceError: Module is not defined
    at opencv.js:46:5
    at opencv.js:11:22
    at node_modules/@techstark/opencv-js/dist/opencv.js (opencv.js:22:1)
    at __require (chunk-OL3AADLO.js?v=3a070356:9:50)
    at dep:@techstark_opencv-js:1:16

Even if I try and use the async function getOpenCv() method that has been updated in the readme I still get the same error, although I'd much rather continue using a standard import statement and avoid refactoring my whole app if possible!

Any help or advice would be greatly appreciated!

Thanks

Simon

ttt43ttt commented 1 year ago

@skmbr please try v4.8.0-release.3

skmbr commented 1 year ago

Thanks!

I don't get any errors now, but it's not firing cv.onRuntimeInitialized :(

ttt43ttt commented 1 year ago

@skmbr do you have a code example so that I can look into it?

skmbr commented 1 year ago

@ttt43ttt The issue occurs with the code in my original post.

If I add a console.log(cv) in mounted() it returns a pending promise so I'm guessing something else has changed since v4.6?

If I go back to 4.6.0-release.1 then cv.onRuntimeInitialized starts firing again.

ttt43ttt commented 1 year ago

@skmbr please try v4.8.0-release.4