-
Notifications
You must be signed in to change notification settings - Fork 10
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
fix multithreaded code causing build errors in Vite #27
Conversation
Attempted to make a test suite on stackblitz, the file upload limit stopped me from uploading the https://stackblitz.com/edit/jsquash27?file=app.vue What is really interesting to me is that stackblitz is the first thing that supports WebAssembly threads. |
Thanks for the submission and work on this! I'll try take a look again next weekend. |
For the |
@CodeF53 I think I may have a solution for use case. When you get a spare moment can you try the following:
Update your Nuxt config with something similar to: import replaceWorkerImportMetaUrl from 'rollup-plugin-replace-worker-import-meta-url';
// https://nuxt.com/docs/guide/directory-structure/nuxt.config
export default defineNuxtConfig({
build: {
transpile: ["@jsquash/oxipng"],
},
vite: {
optimizeDeps: {
exclude: ["@jsquash/oxipng"],
},
plugins: [replaceWorkerImportMetaUrl()]
},
}); I think 🤞 this may solve yours and others problems with Vite and Nuxt. Thanks again! Edit: The above might work, but it's not the correct solution. The |
Doesn't work for me
I can't be bothered to make a minimum viable recreation right now, so here is my repo with those changes applied |
Thanks @CodeF53! It's also really useful sometimes to see how the code is actually used. I can get the fix working if I also add the plugin to import replaceWorkerImportMetaUrl from 'rollup-plugin-replace-worker-import-meta-url';
// https://nuxt.com/docs/guide/directory-structure/nuxt.config
export default defineNuxtConfig({
build: {
transpile: ["@jsquash/oxipng"],
},
vite: {
optimizeDeps: {
exclude: ["@jsquash/oxipng"],
},
plugins: [replaceWorkerImportMetaUrl()]
},
worker: {
format: 'es',
plugins: [replaceWorkerImportMetaUrl()],
},
}); Although this fix is not correct, it will make Vite completely ignoring bundling the multi threaded workers 😅 . I've created PR in Vite and will see if we can get support to fix it, that will be the actual solution 🤞 |
Thanks again for the PR @CodeF53 👏 , I'll close this as unfortunately it doesn't solve the root problem. We now have a quick solution for your needs, I have published special single thread only builds of the following packages:
The long term solution would be to get this bug fixed in Vite. If you can help give a thumbs up/heart reaction on this issue and PR it would help let maintainers know the popularity and scope of users interested in a solution 🙏 |
Explanation of changes
This is the problematic code used in starting multithreaded workers that lead to Vite builds breaking
I replaced all instances of that code with this:
Which is effectively identical to the code in the context I found it in.
Testing
This fixes builds in Vite for me, and works perfectly for all my tests of the example code and OxiPNG.
Problem is, I could not replicate a scenario in which the multi threaded code is ran, as I can't get into a context where
wasmFeatureDetect
thinks supports threads.Given this test for wasmFeatureDetect.threads(), 0/8 people I asked had a device/browser that gave
WebAssembly threads support: true
. So I can't find anyone that could test this code for me