webpack: `new Worker(import.meta.url)` doesn't work as expected

Bug report

I have code like this:

new Worker(import.meta.url)

where module spawns itself as a Worker when multithreading is enabled.

What is the current behavior?

Webpack transforms import.meta.url into a file: URI, which fails to get spawned in runtime.

What is the expected behavior?

Handling of

new Worker(import.meta.url)

should be equivalent to

new Worker(new URL('explicit-own-filename.js', import.meta.url))

which Webpack already supports.

Other relevant information: webpack version: 5.20.1

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Comments: 17 (11 by maintainers)

Most upvoted comments

@sbc100 I implemented support - https://github.com/webpack/webpack/pull/19279

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.