Skip to content
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

vite-wasm-plugin does not work with serviceworker #655

Closed
ffreddow opened this issue Jan 29, 2024 · 7 comments · Fixed by #629
Closed

vite-wasm-plugin does not work with serviceworker #655

ffreddow opened this issue Jan 29, 2024 · 7 comments · Fixed by #629
Labels
bug Something isn't working enhancement New feature or request

Comments

@ffreddow
Copy link

When trying to build a service worker that imports Webassembly I get the same error as if vite-plugin-wasm is not there:

"ESM integration proposal for Wasm" is not supported currently. Use vite-plugin-wasm or other community plugins to handle this. Alternatively, you can use .wasm?init or .wasm?url. See https://vitejs.dev/guide/features.html#webassembly for more details.

Building for developement does not throw an error but there is no serviceworker present.
Without the wasm import everything works just fine.

The config looks like this:
image

Am I configuring this wrong, is it a problem with VietPWA or is it a problem with the wasm plugin.

@ffreddow
Copy link
Author

ffreddow commented Jan 29, 2024

Update:
It works (at least for production builds) when also providing the plugins directly to vite's build function inside src/modules.tsx of VitePWA.
image

@userquin userquin added the bug Something isn't working label Jan 31, 2024
@userquin
Copy link
Member

configured plugins should be added to Vite's plugins entry, we need another entry

@userquin userquin added the enhancement New feature or request label Jan 31, 2024
@userquin
Copy link
Member

It works (at least for production builds) when also providing the plugins directly to vite's build function inside src/modules.tsx of VitePWA.

does the sw work running the app via local preview? what's the top level await plugin?

I'm going to add a new vitePlugins option in this PR: #629

@userquin
Copy link
Member

userquin commented Feb 10, 2024

@ffreddow do you have a reproduction where I can test the changes?

@userquin
Copy link
Member

@ffreddow can you test with new v0.18.0 version using injectManifest.buildPlugins.vite?

@ffreddow
Copy link
Author

ffreddow commented Feb 12, 2024

I created reproduction repository (https://github.com/ffreddow/vite-pwa-plugins-reproduction).
I still get the same error when running the dev server. The production build looks fine when staring at it but something doesn't work out with the preview (probably because of a dynamic import, which is afaik forbidden in a serviceworker, so I guess that's not a problem with VitePWA).

@userquin
Copy link
Member

userquin commented May 5, 2024

You need to register both plugins in vite and inject manifest vite plugins: in dev, the pwa plugin will use vite (no build) and so you need both plugins in vite, on build, pwa plugon will use a new vite build from the api, the build will not use main vite plugins it will use the configured inject manifest vite plugins

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants