GoogleChromeLabs / comlink

Comlink makes WebWorkers enjoyable.
Apache License 2.0
11.24k stars 386 forks source link

Comlink setup with Webpack 5 & React #565

Open RonGootman opened 2 years ago

RonGootman commented 2 years ago

Anyone can provide an example of comlink setup with webpack 5?

Webpack 5 supports work with web-workers natively therefore I used the following syntax to import my worker

const heavyCalc = new Worker(new URL('./heavyCalc.worker.js', import.meta.url));

That works absolutely fine on local environment.

Once a run a build on my React app and deploy it I get the following error 989.e091b9fb8db3edae7192.js:1 Uncaught TypeError: o.h is not a function

to be more precise: o.u = e=>443 === e ? "443.c16ce60f72c403c299d8.js" : e + ".bundle." + o.h() + ".js",

rubenaprikyan commented 2 years ago

Anyone can provide an example of comlink setup with webpack 5? @surma we are using this in a production mode, and comlink is the only blocker to switch to react18(webpack5), any suggestion ?

benjamind commented 1 year ago

Haven't had any specific problems with using webpack v5 and comlink, here's an example sandbox

benjamind commented 1 year ago

Will close this as invalid in the next couple of weeks unless someone can show a reproducible case different than the example sandbox above thats showing an issue.

GregorioF2 commented 1 year ago

I was having issues with loading workers with comlink and Webpack 5. And ended up being a dumb issue with a dependency, i had correctly webpack on version 5.75.0, but I had webpack-cli, set to 4.9.2. When I upgraded webpack-cli to 5.0.1 all started to work fine again

Waqqars987 commented 5 months ago

Works fine during development but getting the below error in production build:

image

React v18 with react-scripts v5.0.1 and comlink-loader v2.0.0.

Some help would be appreciated.

chihiroxc commented 4 months ago

Works fine during development but getting the below error in production build:

image

React v18 with react-scripts v5.0.1 and comlink-loader v2.0.0.

Some would be appreciated.

Met the same issue in development.

react 18.2.0 webpack 5.91.0 comlink 4.3.1

But I didn't use comlink-loader.