wasm-pack icon indicating copy to clipboard operation
wasm-pack copied to clipboard

wasm.greet is not a function

Open shijianzhong opened this issue 2 years ago • 7 comments

🐛 Bug description

Describe your issue in detail. image image

🤔 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

shijianzhong avatar May 20 '22 13:05 shijianzhong

image

shijianzhong avatar May 20 '22 13:05 shijianzhong

I was able to resolve this issue with the following:

  1. on the rust side run: wasm-pack build --target web

  2. 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/"] }}})

ruhibloodworth avatar Jun 10 '22 21:06 ruhibloodworth

Why is initialisation necessary? On the rustwasm.github.io hello-wasm tutorial it is not used...

milovangudelj avatar Nov 18 '22 12:11 milovangudelj

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.

airinterface avatar Dec 16 '22 22:12 airinterface

I have the same question. Why should we do init()? Why doesn't the example code hello-world?

weirenxue avatar Jun 02 '23 06:06 weirenxue

is there any update on this?

donkey-donkey avatar Sep 20 '23 23:09 donkey-donkey

Still have this issue. Any ideas or updates ?

Sellig6792 avatar Apr 09 '24 21:04 Sellig6792