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 a year ago
  • Comments: 35 (5 by maintainers)

Commits related to this issue

Most upvoted comments

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):

import init, { function } from './pkg/xxx.js';
// Without async/await
init().then(() => {
    function();
  });
// With async await
await init();
function();

Or (with wasm-pack build --target bundler):

import { function } from './pkg/xxx.js';
function();

Edit: Here is an example with --target web: wasm.html

I don’t know sorry 😕

@FlareFlo What version of Webpack are you using? I’m running webpack 5.75.0, apparently it doesn’t need such loaders anymore, instead, we’ve got these options turned on:

    experiments: {
      asyncWebAssembly: true,
      syncWebAssembly: true,
    },

I have these options set using 5.75.0

I’m glad I’m not the only one seeing this! It’s driving me crazy 😭

My development branch has been offline for 2 weeks, I thought I had just misconfigured the webserver somehow.