wasm-bindgen: Undefined `__wbindgen_malloc` when running WASM binary
Describe the Bug
We’ve recently hit a snag from compiling the same code and getting different results a few weeks apart.
2 weeks ago, we published this bundle: https://unpkg.com/browse//bitmask-core@0.5.0-rc.6/
It was built from this repo and commit: https://github.com/diba-io/bitmask-core/commit/5cf7f4d64354e4979b9d5d74c8c83871f1627e83
Using this command: wasm-pack build --release --target bundler
Back then, it produced a binary that runs in our Chrome extension, but now it produces something different, where running any function results in this error:
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading '__wbindgen_malloc')
I’m not sure what steps I can try to investigate this further.
Examples of more recent tries:
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 36 (5 by maintainers)
I don’t think there is an init function when using bundler, only when targeting web
So either you have (with
wasm-pack build --target web):Or (with
wasm-pack build --target bundler):Edit: Here is an example with
--target web: wasm.htmlI don’t know sorry 😕
and the “Uncaught (in promise) TypeError: Cannot read properties of undefined (reading ‘__wbindgen_malloc’)” error goes away…
I have these options set using
5.75.0I’m using vite with this config (entire)
I believe even in webpack you’ll need to touch the config, but I don’t know webpack
Yes absolutely. You can read up on it here: https://rustwasm.github.io/docs/wasm-bindgen/examples/without-a-bundler.html.
I can only assume that
wasm-packkinda does this for you, but in the example that was posted above a custom HTML was used that doesn’t callinit(). Again, I have no clue aboutwasm-pack, just speculating.My development branch has been offline for 2 weeks, I thought I had just misconfigured the webserver somehow.
I’m getting either
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading '__wbindgen_add_to_stack_pointer')orUncaught (in promise) TypeError: Cannot read properties of undefined (reading 'main_js')wheremain_jsis a rust fn annotated with#[wasm_bindgen(start)]. Occurs both on windows and Linux.