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

Add __wbindgen_throw to importObject #1

Closed
wants to merge 1 commit into from
Closed

Add __wbindgen_throw to importObject #1

wants to merge 1 commit into from

Conversation

andrewdavidmackenzie
Copy link

I was following your serverless-rust tutorial on my own.

I was getting an error in the CloudFlare Script editor on save, that the function __wbindgen_throw was missing :

Uncaught LinkError: WebAssembly Instantiation: Import #2 module="./serverless_rust" function="__wbindgen_throw" error: function import requires a callable at line 79 in mod at line 87

Using

wasm-objdump pkg/serverless_rust_bg.wasm -x

it seems my WASM is importing "__wbindgen_throw":

....deleted lines....
Custom:
 - name: "name"
 - func[0] <__wbg_alert_a6f756c1262c4809>
 - func[1] <__wbg_now_7e59c3475b182c97>
 - func[2] <__wbindgen_throw>
....deleted lines....

and I saw it was implemented in the generated JS:

 function __wbindgen_throw(ptr, len) {
      throw new Error(getStringFromWasm(ptr, len));
  }

so I added it to the importObject:

  const importObject = {
    './serverless_rust': {
        __wbg_alert_a6f756c1262c4809,
        __wbg_now_7e59c3475b182c97,
        __wbindgen_throw
    }
  };

(those are my function references, won't coincide with your code)....

and everything worked!

This maybe caused by some update to the wasm-bindgen or wasm-pack since you wrote the tutorial maybe?

When following the tutorial on my own, it seems my WASM is importing "__wbindgen_throw", and I saw it implemented in the JS, and I was getting an error on it being missing in the CloudFlare Script editor, so I added it to the importObject and everything worked.
@stevenpack
Copy link
Owner

Thanks Andrew! I don't have the environment setup anymore to try this out but I've updated the blog post with a link to your PR and a credit to help folks find their way. https://blog.cloudflare.com/cloudflare-workers-as-a-serverless-rust-platform/

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

Successfully merging this pull request may close these issues.

None yet

2 participants