Jump to content

WASM: Uncaught (in promise) TypeError: Import #0 module=“env” error: module is not an object or function Promise.then (async) (anonymous) @ (index):9


NonBinary
 Share

Recommended Posts

I'm new to emscripten and find it very hard... I have obligation to work on windows because i have to test .exe versions of my apps. I'm on windows 7.

I can compile wasm but javascript cannot read it. Here's my code.

C code:

char * HelloWorld ()
{
    return "Hello World !";
}

Emscripten command-line:

emcc hello.c -O2 -s ONLY_MY_CODE=1 -s WASM=1 -s SIDE_MODULE=1 -s EXPORTED_FUNCTIONS="['_HelloWorld']" -o hello.wasm

Wat result:

(module
  (type $t0 (func (result i32)))
  (type $t1 (func))
  (import "env" "memory" (memory $env.memory 256))
  (import "env" "memoryBase" (global $env.memoryBase i32))
  (func $_HelloWorld (export "_HelloWorld") (type $t0) (result i32)
    (get_global $env.memoryBase))
  (func $__post_instantiate (export "__post_instantiate") (type $t1)
    (set_global $g1
      (i32.add
        (get_global $env.memoryBase)
        (i32.const 16)))
    (set_global $g2
      (i32.add
        (get_global $g1)
        (i32.const 5242880))))
  (global $g1 (mut i32) (i32.const 0))
  (global $g2 (mut i32) (i32.const 0))
  (data (get_global $env.memoryBase) "Hello World !"))

Javascript:

importObject = {};

fetch('hello.wasm').then(response =>
  response.arrayBuffer()
).then(bytes =>
  WebAssembly.instantiate(bytes, importObject)
).then(results => {
  console.log("loaded");
});

Error message:

Uncaught (in promise) TypeError: Import #0 module="env" error: module is not an object or function
Promise.then (async)
(anonymous) @ (index):9

Can you tell me what's wrong in my code ?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...