threads.js
threads.js copied to clipboard
Parcel 2 compatibility
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?
Hey @lgarron! Is the importScripts() call part of your worker code or is it threads.js that adds it?
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.
Anything simple I could do to help debug this?
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.
@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.
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.
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
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.
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.)
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.
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)…
What solution did you end up with? I hate how much of my life is wasted on build pipelines
We just kept using Parcel v1 😄