Closed hschimke closed 1 year ago
It has nothing to do with this plugin. Your code is importing the wasm-pack package from Node.js (not from web, not in Vite's bundle, directly from your Node.js) but the package generated by wasm-pack has no "main"
field, which is required by Node.js.
Adding "main"
and "type"
fields resolves this error:
{
// ...
"module": "rxing_wasm.js",
"main": "rxing_wasm.js",
"type": "module",
// ...
}
You also need --experimental-wasm-modules
for importing WASM file directly from Node.js: export NODE_OPTIONS=--experimental-wasm-modules
.
Since your error is nothing to do with this plugin and even Vite. It's more a Node.js ESM related issue. I'll close it.
Maybe you can open an issue on wasm-pack.
Thanks for taking a look, much appreciated!
Additionally, this plugin should works with SSR and SvelteKit (the server bundle should work). I don't use SvelteKit but when debugging with others' SvelteKit project I didn't find it's running your code directly in Node.js. Maybe you should check your SvelteKit configuration, which I can't help...
This is likely because I have mine configured to disable SSR. The intended target of the app is an Azure Static Web Site. The expected behavior is bundling and loading in the browser from the _app/immutable/assets path.
I had hoped that the update to wasm-pack and wasm-bindgen would resolve some of my issues but I'm still blocked on their sideEffects bug (and reading through other bug reports it looks like adding "main" and "type" aren't in the next build either).
But, thanks to your help, I created a properly configured package.json and posted a new version of the rxing-wasm module. Everything seems to work correctly now, thank you again for your help!
A sample repository with this error is available at: https://github.com/hschimke/rxing-sveltekit
When testing, everything works correctly and the program works as expected (
npm run dev
).When building for production, however, I receive the following output:
linux:
npm:
node: