wasm-pack
wasm-pack copied to clipboard
wasm.greet is not a function
🐛 Bug description
Describe your issue in detail.
🤔 Expected Behavior
What should have happened?
👟 Steps to reproduce
Clear steps describing how to reproduce the issue, including commands and flags run. If you are seeing an error, please include the full error message and stack trace.
🌍 Your environment
Include the relevant details of your environment. vite+vue3 wasm-pack version:0.10.2 rustc version:1.58.1
I was able to resolve this issue with the following:
-
on the rust side run: wasm-pack build --target web
-
on the javascript side use: import init, {greet} from "../pkg";
init().then((_exports) => { greet(); });
3: modify vite.config.ts to serve the wasm file. export default defineConfig({ ... server: { fs: { allow: [".","../pkg/"] }}})
Why is initialisation necessary? On the rustwasm.github.io hello-wasm tutorial it is not used...
I asked for the pull request. Pull Request This might be the problem. I found that generated js file doesn't import default export correctly if you use wasm-bindgen to generate the js files.
I have the same question. Why should we do init()? Why doesn't the example code hello-world?
is there any update on this?
Still have this issue. Any ideas or updates ?