question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Modifying URL in web worker chunk

See original GitHub issue

I’m running to issues with an inline web worker with a dynamic import not being intercepted by this library. Since inline web workers are blobs and therefore need an absolute URL to successfully import scripts, I’m attempting to use this library to fix-up the URL.

e.g.

const md = await import(/* webpackChunkName: "markdown-it" */ 'markdown-it');

inside a web worker becomes something like

const md = await __webpack_require__.e(/* import() | markdown-it */ 2).then(__webpack_require__.t.bind(null, 264, 7));

which calls into

r.e = function(e) {
        var n = [];
        return n.push(Promise.resolve().then(function() {
            t[e] || importScripts(e + ".ee0bc93119ec2d63cc28.worker.js")
        })),
        Promise.all(n)
    }

Unfortunately, this isn’t prepending the path it should be per the config below since it never actually results in the code below being called.

Object.defineProperty(r, "p", {
        get: function() {
            return "http://localhost:8080/"
        }
    }),
new WebpackRequireFrom({
      path: 'http://localhost:8080/',
      suppressErrors: true,
    }),

(For now, I’ve used a hardcoded path to see if I could get it minimally working. In practice, it would be a variable that is set similar to the advice in https://stackoverflow.com/a/22582695/1266600.)

Am I misunderstanding how something works or perhaps the intent of this library?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
agoldiscommented, Apr 9, 2019

Great, I will roll out a new npm release later this week

Read more comments on GitHub >

github_iconTop Results From Across the Web

how to change the output format of web worker files in ...
const workerUrl = new URL( /* webpackChunkName: 'pdf.worker' ... which I was able to control the output directory of the web worker bundle....
Read more >
Web Workers | webpack - JS.ORG
As of webpack 5, you can use Web Workers without worker-loader . Syntax. new Worker(new URL('./worker.js', import.meta.url)); // or customize the chunk name ......
Read more >
Inline worker in webpack 5 · Discussion #14066 - GitHub
I need to host all assets in CDN, but Web Worker requires the same domain policy. ... relative/path/to/my/worker.js?inline'), import.meta.url).
Read more >
Develop Faster JS Apps: the Ultimate Guide to Web Workers
In this tutorial, we'll introduce web workers and demonstrate how you can use them to address execution speed issues. Contents:.
Read more >
Using Web Workers - Web APIs - MDN Web Docs
Web Workers are a simple means for web content to run scripts in background threads. The worker thread can perform tasks without interfering ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found