-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
With a pthread build, and bundled with webpack, creation of new Web Worker fails due to protocol=file: in import.meta.url #22521
Comments
Is The |
I was thrilled when I saw #22165 because I was having the same issue, and that did resolve it in that case. So a qualified 'yes' to |
If you do @RReverser any insights here? I'm under understanding things right? |
Sounds right. Webpack needs specifically the |
You're right. That and the file: protocol getting used for import.meta.url led me to exclude my.js from the webpack bundle, putting it in the same directory as my.wasm. But that only works if I can pass down the URL so it can be picked up where the worker is created.
I've put together as minimal an example as I could into repo emsdk_pthread_nested_webpack if anyone has time to take a look. Another interesting note is that webpack duplicates my.js. It puts it once in a hash-named file, and once in MyWasm.min.js. And it also gives a circular dependency warning. However, if I exchange: |
Right, I guess when you do Not that in both cases don't you end up two seprate copies of the main js file? You either end up using a hash-named file or you end up using your original This seems unfortunate and kind of defeats the point of bundles doesn't it? i.e. without bundling you just have a single my.js file, but with bundling that code in my.js exists in two different files that must be downloaded to the client separately. Is the right @RReverser ? |
I apologize for neglecting this - I had to switch tasks for a bit. I appreciate your comments and questions up to this point.
@sbc100, like you said, I end up with two copies, one bundled and one not. So I'll still be probing for a real solution. But it does get me past this for the moment. |
Version of emscripten/emsdk: 3.1.64
Please include the output
emcc -v
here:Failing command line in full: N/A
Full link command and output with
-v
appended:Issue: With a pthread build, and bundled with webpack, creation of new Web Worker fails due to protocol=file: in import.meta.url.
The short description is that I have a project (project-A) where we are compiling our WASM target with
-pthread
. Project-A is bundled with webpack. Project-A is in turn used by project-B, which also uses webpack as a bundler, so the bundling is nested. In the Module JS file, the lineworker = new Worker(new URL("my.js", import.meta.url), workerOptions);
fails because the protocol ofimport.meta.url
is ‘file:
’.I have not been able to find a webpack-based way to work through this issue. The workaround I have involves hand-editing my.js to do the following (minus error checking here):
worker = new Worker(Module["wasmJsURL"].href, workerOptions);
, wherewasmJsURL
is ascertained by the main application since it understands thelocation.origin
and path, and it can send the complete URL during instantiation of the WASM JS Module objectnew MyAppWASM( { instantiateWasm: onInstantiateWasm, noExitRuntime: true, wasmJsURL: this.wasmJsURL } )…
.Might there be another approach that I’m not aware of? I can put a minimal example in a github project if needed. Or is it a valid request to have Emscripten offer the ability for passing the WASM JS URL during instantiation for use in Worker creation?
Here are a few references I've collected that have, or may have, bearing:
#22140
#20580
#16878
The text was updated successfully, but these errors were encountered: