worker-plugin icon indicating copy to clipboard operation
worker-plugin copied to clipboard

Error when using comlink

Open alshdavid opened this issue 4 years ago • 0 comments

Hi, thanks for putting together this loader. Having an issue with integrating comlink.

main.ts

void async function() {
  const worker = new Worker('./test.js', { type: 'module' })
  const TestStore = Comlink.wrap(worker)
  console.log(await new TestStore())
}()

test.js

import { expose } from 'comlink'

class Thing {
  constructor() {
    this.state = ''
  }

  setState(v) {
    this.state = v
  }
}

expose(Thing)

results in the error

Uncaught (in promise) TypeError: Cannot read property 'apply' of undefined
    at MessagePort.eval

I am using the latest Chrome

alshdavid avatar Aug 15 '19 14:08 alshdavid