question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using comlink with GoogleChromeLabs/worker-plugin

See original GitHub issue

Hi team, love your work. Having some trouble integrating google’s worker plugin.

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

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:7
  • Comments:14

github_iconTop GitHub Comments

17reactions
2213397919commented, Oct 12, 2019

能将解一下如何在React项目中使用它吗

3reactions
ritz078commented, Sep 8, 2019

This error is also there with worker-loader

Read more comments on GitHub >

github_iconTop Results From Across the Web

Integrating web workers in a React app with Comlink
Google's Comlink library makes interacting with web workers much more elegant. Explore a real-world use case by integrating a web worker ...
Read more >
Simplify Web Worker code with Comlink - David East
But if workers are so great, why are they so under utilized? Are UI performance issues not common? That can't be the case...
Read more >
How to use the comlink.expose function in comlink - Snyk
To help you get started, we've selected a few comlink examples, based on popular ways it is used in public projects. Secure your...
Read more >
Enjoyable WebWorkers in Angular. With Comlink - Medium
Angular CLI v8.3 supports Web Worker module as a built-in feature! ... Comlink has its own TypeScript definition in the package, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found