You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
new Worker(import.meta.url) doesn't work as expected #12638
Having thought about this a bit more, while I think it would be useful, it's likely not the most uncommon usecase and other bundlers don't seem to support this either. To keep consistency I suppose I'll close it.
This is by far the most common usage of new Worker in emscripten since this is how we spawn new pthreads. With pthreads every worker runs exactly the same code so new Worker(import.meta.url) is the most logical choice.
It's mostly hard because you'd have to implement it in every possible bundler out there. I think keeping that pattern is a much easier, if somewhat unfortunate, choice.
I believe this is the only bundler that doesn't support new Worker(import.meta.url) now. Do you know of another? I did some basic testing with vite and it seems to support new Worker(import.meta.url)
I did some basic testing with vite and it seems to support new Worker(import.meta.url)
I tried it on vite with dynamic chunks (without dynamic chunks all works fine), looks like it is buggy (not sure it was reported),
Can you elaborate? I'd like to write a test on the emscripten side the proves (or disproves) such bundling is working correctly. i.e. can you explain what that buggy-ness is?
There is a small limitation, when you try to bundle such code, you will get:
WARNING in [entry] [initial]
Circular dependency between chunks with runtime (main, test_js)
This prevents using hashes of each other and should be avoided.
This is just a warning, and bundling itself will compile successfully. It only warning about you can't use chunkFilename: "[hash].js. I plan to solve this in the future too, but it requires a little more work. Currently you can ignore such warning.
Awesome, thanks for working this! In our case we absolutely do have a fundamental circular dependency of course. Hopefully that can be ignored by users or fixed.
Activity
luvsta commentedon Mar 23, 2021
script tag must be support ESM.
webpack-bot commentedon Jun 22, 2021
This issue had no activity for at least three months.
It's subject to automatic issue closing if there is no activity in the next 15 days.
alexander-akait commentedon Jun 22, 2021
Still valid
RReverser commentedon Jun 23, 2021
Having thought about this a bit more, while I think it would be useful, it's likely not the most uncommon usecase and other bundlers don't seem to support this either. To keep consistency I suppose I'll close it.
alexander-akait commentedon Jun 23, 2021
@RReverser I think we can keep open, for me it is feature/enhancement than bug
devongovett commentedon Jul 18, 2021
FYI I just implemented support for this in Parcel (see link above). Came across this issue while I was researching so thought I would let you know. 😉
RReverser commentedon Jul 18, 2021
Ah thanks :)
2 remaining items
webpack-bot commentedon Nov 2, 2021
Issue was closed because of inactivity.
If you think this is still a valid issue, please file a new issue with additional information.
sbc100 commentedon Mar 3, 2025
Any idea who hard it would be address this?
Over in emscripten we currently jump through a bunch of hoops to avoid
new Worker(import.meta.url)but that is really what we want to generate here: https://github.com/emscripten-core/emscripten/blob/b8b827affe7090dda4a115fbbc6dea0b6046575e/src/lib/libpthread.js#L434-L438This is by far the most common usage of
new Workerin emscripten since this is how we spawn new pthreads. With pthreads every worker runs exactly the same code sonew Worker(import.meta.url)is the most logical choice.See https://github.com/emscripten-core/emscripten/pull/23804/files#r1978395660
RReverser commentedon Mar 4, 2025
It's mostly hard because you'd have to implement it in every possible bundler out there. I think keeping that pattern is a much easier, if somewhat unfortunate, choice.
sbc100 commentedon Mar 4, 2025
It more than a little unfortunate. Have you seen what this PR proposes: emscripten-core/emscripten#23804?
I believe this is the only bundler that doesn't support
new Worker(import.meta.url)now. Do you know of another? I did some basic testing with vite and it seems to supportnew Worker(import.meta.url)RReverser commentedon Mar 4, 2025
It's a bit old by now, but back in https://web.dev/articles/bundling-non-js-resources we listed WebPack, Rollup, Parcel and Vite as those supporting the new (at the time) idiom of
new URL(..., import.meta.url), either directly or via plugins.Sounds like Vite supports this shorter syntax now, and WebPack doesn't, what about e.g. Parcel?
alexander-akait commentedon Mar 4, 2025
I tried it on vite with dynamic chunks (without dynamic chunks all works fine), looks like it is buggy (not sure it was reported),
sbc100 commentedon Mar 4, 2025
Can you elaborate? I'd like to write a test on the emscripten side the proves (or disproves) such bundling is working correctly. i.e. can you explain what that buggy-ness is?
alexander-akait commentedon Mar 4, 2025
@sbc100 I implemented support - #19279
There is a small limitation, when you try to bundle such code, you will get:
This is just a warning, and bundling itself will compile successfully. It only warning about you can't use
chunkFilename: "[hash].js. I plan to solve this in the future too, but it requires a little more work. Currently you can ignore such warning.sbc100 commentedon Mar 11, 2025
Awesome, thanks for working this! In our case we absolutely do have a fundamental circular dependency of course. Hopefully that can be ignored by users or fixed.
Is there a reason this bug is still open?
alexander-akait commentedon Mar 11, 2025
To fix a warning, we can avoid it, so I will close when it will be fixed 😄
alexander-akait commentedon Jan 26, 2026
Fixed by #20345