-
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
URL path generated for Worker imports doesn't work with Webpack #22140
Comments
Hmm.. it seems odd to me that If webpack is expanding |
Regarding the self-dependency, do we really want to suppress that warning? I mean, the file really does depend on itself.. that is how it works.. we don't want webpack to thing any different do we? |
@RReverser does |
I hadn't found it in the docs earlier, but looking at webpack's docs on
So it sounds like In the native worker support section they mention using the Omitting the |
I'm trying to reproduce the issue using webpack in our test harness, but I'm struggling to do so. I've added a webpack test that includes EXPORT_ES6 here: #22142 However, I can't seem to make it work with pthreads, with or without EXPORT_ES6. |
Yeah the former is recognised as a pattern by a lot of bundlers, but the latter isn't, even though in runtime they'd be the same, yes. |
Damn.. thats kind of a shame. IMHO, the later is much cleaner since its independent of that actual filename. The former requires that extra tempting step, more characters, and is not portable across file renames. |
I've hit this issue as well after recently updating emsdk. What is the disposition here? Is there a workaround that doesn't involve manual patching? |
I'd be happy to see a PR submitted to fix this, and hopefully it can come with and update to |
The issue may have been missing the |
…e with bundlers (#22165) This PR closes #22140 by updating the URL used to import the worker JS in `library_pthread.js::allocateUnusedWorker`. Previously the URL would be: ```js worker = new Worker(new URL(import.meta.url)) ``` which webpack translates to the`file:///` path, causing the import to fail b/c the `file://` path is not valid to access ([webpack docs import meta](https://webpack.js.org/blog/2020-10-10-webpack-5-release/#importmeta)).
Hi, I'm setting up a C++ WASM app to use threads that I distribute as part of a frontend app that uses webpack, however I'm running into an issue with how webpack is handling the URL for the worker import. In Emscripten's generated JS, the worker file is imported in
allocateUnusedWorker
as:Webpack seems to resolve this import URL to a local
file://
path, producing:which results in the following error when trying to run the app, since the URL import path is not valid:
If I patch the function to change the import URL to (where
script_filename.js
is the name of the JS output file) webpack is able to resolve the path correctly:It also works without the
.href
, though webpack will then complain about circular dependencies between the files breaking filename hashing (since the file now depends on itself).I noticed that this is the same URL structure that
findWasmBinary
returns to be compatible with bundlers:emscripten/src/preamble.js
Line 617 in d079eca
The full project code is here: https://github.com/Twinklebear/webgpu-cpp-wasm/tree/threads if you want to test it, the patch step can be removed by commenting out this line in src/CMakeLists.txt or just making the patch script a noop.
Or if I'm doing something wrong with my webpack config to import these files, let me know.
Version of emscripten/emsdk:
The text was updated successfully, but these errors were encountered: