threads.js icon indicating copy to clipboard operation
threads.js copied to clipboard

Parcel 2 compatibility

Open lgarron opened this issue 4 years ago • 13 comments

I've been scratching my head about how to build compatible workers, and this library is the most promising so far! Unfortunately, I use Parcel 2, and the basic demo runs into an error. 😢

auth.bd78dd40.js:1 Uncaught DOMException: Failed to execute 'importScripts' on 'WorkerGlobalScope': The URL './index.d6afe8b1.js' is invalid.
    at http://localhost:1234/auth.bd78dd40.js:1:1
    at blob:http://localhost:1234/13b36260-4ae6-4c43-845c-0dfccc529f9c:1:1

I thought I found a reference suggesting that you can't use this kind of relative path from a blob, but Parcel 2 can definitely handle workers in general (e.g. libraries like comlink work with parcel server). However, I can't seem to find that again.

I'd really like to use threads.js, but this is a big blocker for our use case. Any thoughts on where best to attempt to address this?

lgarron avatar Nov 20 '20 05:11 lgarron

Hey @lgarron! Is the importScripts() call part of your worker code or is it threads.js that adds it?

andywer avatar Nov 20 '20 07:11 andywer

Hey @lgarron! Is the importScripts() call part of your worker code or is it threads.js that adds it?

This is with the sample code, so it's either threads.js or Parcel 2 that adds it!

Here's a repro, which is basically the sample code: https://github.com/lgarron/parcel-2-threads-repro

node master.js works in that repro, but npx parcel index.html runs into the error above.

lgarron avatar Nov 20 '20 11:11 lgarron

Anything simple I could do to help debug this?

lgarron avatar Dec 05 '20 01:12 lgarron

Hmm, good question. Could you post the line with the failing importScripts() and the surrounding couple of lines?

Unfortunately I've already got a quite extensive backlog, so I'm afraid I won't have much time to look into this. If we can figure out the root of the issue, I could quickly prepare a fix, though.

andywer avatar Dec 05 '20 10:12 andywer

@lgarron long shot here but have you gotten it to work? I am having the same issue when I try to do a test using a simple function that returns a string and nothing seems to happen.

simplecommerce avatar Jan 27 '21 18:01 simplecommerce

Unfortunately not. I've given up on having a good development flow for web workers while several Parcel issues are still outstanding:

https://github.com/parcel-bundler/parcel/issues/5504 https://github.com/parcel-bundler/parcel/issues/5473 https://github.com/parcel-bundler/parcel/issues/3959

I'm hoping to give it another try once those issues are in a better place.

lgarron avatar Jan 27 '21 21:01 lgarron

Also, the lack of module workers in Firefox/Safari is a real pain, along with some other things that are hard for Parcel and this library to work around:

https://github.com/lgarron/web-worker-compat-problems

lgarron avatar Jan 27 '21 21:01 lgarron

Are you on nightly or next? Nightly fixes some of the module resolution logic but importing the same dependency from different webworkers creates bundling issues at the moment I think.

ProLoser avatar Jan 30 '21 00:01 ProLoser

Are you on nightly or next? Nightly fixes some of the module resolution logic but importing the same dependency from different webworkers creates bundling issues at the moment I think.

Ooooh, the latest nightly fixes https://github.com/lgarron/parcel-2-threads-repro

(The bundling issues are still a blocker for me, though.)

lgarron avatar Jan 30 '21 02:01 lgarron

https://github.com/parcel-bundler/parcel/issues/5430 I'm trying to get audio worklet detection working, if I can just login to opencollective and sponsor them for their hard work lol.

ProLoser avatar Jan 30 '21 02:01 ProLoser

Great to see you all are looking into this! I tried getting threads.js to work with Parcel 2 like one and a half years ago or so, but I gave up at some point as I would have needed to spend much more time on this and a lot of Parcel 2 felt very early stage back then.

I was hoping that by now they would have fixed most of the issues, though. Maybe not (yet)…

andywer avatar Jan 31 '21 17:01 andywer

What solution did you end up with? I hate how much of my life is wasted on build pipelines

ProLoser avatar Jan 31 '21 18:01 ProLoser

We just kept using Parcel v1 😄

andywer avatar Jan 31 '21 18:01 andywer