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

wasm.greet is not a function #1140

Open
shijianzhong opened this issue May 20, 2022 · 7 comments
Open

wasm.greet is not a function #1140

shijianzhong opened this issue May 20, 2022 · 7 comments

Comments

@shijianzhong
Copy link

🐛 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
Copy link
Author

image

@ruhibloodworth
Copy link

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

@milovangudelj
Copy link

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

@airinterface
Copy link

airinterface commented Dec 16, 2022

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.

@weirenxue
Copy link

weirenxue commented Jun 2, 2023

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

@donkey-donkey
Copy link

is there any update on this?

@Sellig6792
Copy link

Still have this issue. Any ideas or updates ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants