-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Bundling a multithreading program, without public URL #23957
Comments
This issue has come up a few times recently. In you case does replacing I've been wanting to switch to that form for a while now but have been blocked on support in bundlers for this simpler syntax. |
See #23769, which was fixed in #23890. Also see #22521 and webpack/webpack#12638 |
Thanks for the quick reply! But since you say this came up recently, and something related was fixed recently, I wanna point out that I'm still using 3.1.64, as that is the latest version available as a nix package. |
Are you using a bundler? If so which one? Presumably |
I'm not using any bundler :) Structure:
(Note that this setup totally works, if I don't use multithreading, which one can test by removing the flags in the CMakeLists.txt. Obviously not an option for my real world usecase) |
Where does the |
Are you sure nextjs isn't doing some kind of bundling? |
Ohhh yeah that's a good point! After running I have no clue where the string comes from tho. If built by NextJS, shouldn't it at least bundle all dependencies in the resulting build-folder? I wonder if this has to do with pnpm-workspaces or something. The dependencies being weirdly linked. But I am so out of my depth in this regard. |
I found the issue!! Emscripten is not at fault, and it's not even some bundling mishap. It's just Next.js. TL;DRThis had nothing to do with any See How I found itThe resulting worker.onerror = (e) => {
var message = "worker sent an error!"
if (worker.pthread_ptr) {
message = `Pthread ${ptrToString(worker.pthread_ptr)} sent an error!`
}
err(`${message} ${e.filename}:${e.lineno}: ${e.message}`)
throw e
} The log prints ConclusionIt's always CORS. |
I have a problem using multithreading and packaging the resulting WASM in a reusable node package.
But let's start with what works so far:
I have a C++ program that I compile with emscripten, utilizing a CMakeLists.txt. I then want to use the resulting WASM in an npm package, for me to later publish.
These are my compiler flags:
It outputs a .js and a .d.ts file, and I can use it like this:
This works well!
However, now I want to add multithreading. I adjust my code, and add the following compiler flags to my CMakeLists.txt:
When running the same way I do above, I get these errors in my console:
I have the strong suspicion, that it is because of this block in the generated .js file:
As I said, I use this in a package, I don't host the hello_world_web.js in any specific place. How would "hello_world_web.js" actually be found? Is there any specific way of handling this?
I already gave "locateFile" a go, like this:
But nothing was logged, and since I don't see any "locateFile" referenced in the codeblock I mentioned, I didn't pursue this any further.
I also looked into webpack, and whether it would solve my issues. But that feels like overkill for what I want to achieve, and I have no clue if that is even the right path. So I didn't get further into that yet either.
Any help would be highly appreciated! Here's a simple repo to try things out: https://github.com/Andonvr/emscripten-threading-example.
Cheers.
The text was updated successfully, but these errors were encountered: