Open nmattia opened 2 years ago
Can you provide a GitHub repository with the reproduction? We get too many bugs filed to create the reproduction for each one
This is either a bug with Vite or Undici and not with SvelteKit itself. It'd be nice to figure out which one so you can file the bug in the right place. https://github.com/sveltejs/kit#bug-reporting
Thanks for the quick reply,
As mentioned in the issue description, I've pushed the code to this repo: https://github.com/nmattia/svelte-rust-wasm/tree/main/sveltekit-app
This is either a bug with Vite or Undici and not with SvelteKit itself.
The repo contains two very similar apps that use the same Wasm module; one is the svelte + vitejs default template, the other one the sveltekit default template. I'm curious why the svelte + vitejs one works out of the box.
EDIT: I've just committed the Wasm code as well. You just just need to run cd sveltekit-app && npm ci && npm run dev
for repro.
I'm curious why the svelte + vitejs one works out of the box.
It's most likely either because the svelte + vitejs one doesn't use SSR (see https://github.com/sveltejs/kit#bug-reporting for details) or because it doesn't use Undici. Either way, you're probably going to need to file this issue elsewhere to see it addressed
Seems related: https://github.com/vitejs/vite/issues/8882
We use wasm-pack generated modules with SSR using this vite plugin: https://github.com/omnysecurity/vite-plugin-wasm-esm. Works well for us, but you have to use web
as target when building with wasm-pack.
Describe the bug
Importing a Wasm module fails, whereas a simple (non-sveltekit) svelte app can load and use the Wasm module just fine.
I'm generating the Wasm module (and project that includes a few js wrappers) using wasm-pack.
Additionally to the repro steps below, I've pushed the code here. This contains three projects:
lib
, a rust library that gets compiled to wasm (to avoid building it, usepkg.zip
attached in "Reproduction" belowsvelte-app
, a (default template) svelte app (without sveltekit) that can make use of the Wasm filesveltekit-app
, a (default template) sveltekit app that fails onnpm run dev
but succeeds onnpm run build
, although the resulting build is broken.Reproduction
Initialize a sveltekit project:
Add necessary dependencies:
Update
vite.config.ts
:Call e.g. the
greet
function from the Wasm module from a page:Run
npm run dev
:I've attached the
pkg/
which contains the Wasm module (can be a bit cumbersome to generate otherwise).pkg.zip
Logs
No response
System Info
Severity
blocking all usage of SvelteKit
Additional Information
No response