0

I'm getting a JS error: Uncaught (in promise) TypeError: WebAssembly.instantiate(): Import #0 module="env" error: module is not an object or function

When I view the wasm file in the Chrome dev tools, I see import statements like this, at the top:

(module
  (func $blst_hash_to_g2 (;0;) (import "env" "blst_hash_to_g2") (param i32 i32 i32 i32 i32 i32 i32))
  (func $blst_sign_pk2_in_g1 (;1;) (import "env" "blst_sign_pk2_in_g1") (param i32 i32 i32 i32))
  (func $blst_scalar_from_bendian (;2;) (import "env" "blst_scalar_from_bendian") (param i32 i32))
  (func $blst_sk_check (;3;) (import "env" "blst_sk_check") (param i32) (result i32))

What is causing these import statements? How can I remove or fix them? I can see they are part of the blst Rust package, which is included by the blsttc package. The blst package uses bindgen to generate FFI bindings to blst.h, so maybe that has something to do with it?

This Github repo has the code. I am building using wasm-pack build --target=web

user1558646
  • 145
  • 4
  • 9
  • As I understand it, the problem is that `env` should be, but isn't being generated by `wasm-pack`. This typically happens for me if the build artifacts get corrupted, which can happen if I abort the build process during code generation. The solution is then to run `cargo clean` to remove the corrupted build artifacts and build the whole project again from scratch. – glennsl Jul 07 '21 at 07:40
  • Since you have a C dependency, are you building with `CC=emcc wasm-pack build --target=web` using emscripten's latest sdk? I've successfully built your github repo using that command. – Mathieu Rene Jul 08 '21 at 00:46
  • @glennsl Cargo clean did not work, but thank you – user1558646 Jul 08 '21 at 03:32
  • @MathieuRene it does not build for me, even with the latest emscripten and CC=emcc. The build process is dying on the blst package with the error "error: failed to build archive: section too large" – user1558646 Jul 08 '21 at 03:33
  • emcc 2.0.25 rustc 1.53.0 wasm-pack 0.10.0 on ubuntu20.04 here, what are your os/component versions? – Mathieu Rene Jul 08 '21 at 04:46
  • Hey @MathieuRene, I switched to Ubuntu 20.04 with latest everything and it works great now. I was on mac os 10.15.7. Thanks for trying it on Ubuntu and helping me realize that something about my mac's setup is the issue. – user1558646 Jul 08 '21 at 07:06

1 Answers1

0

I fixed this by switching to Ubuntu 20.04 with latest everything and it works great now. I was on mac os 10.15.7.

user1558646
  • 145
  • 4
  • 9