GoogleChromeLabs / worker-plugin

👩‍🏭 Adds native Web Worker bundling support to Webpack.
https://npm.im/worker-plugin
Apache License 2.0
1.91k stars 79 forks source link

Error when using comlink #37

Closed alshdavid closed 1 year ago

alshdavid commented 5 years ago

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