user714171
user714171

Reputation: 435

TypeError: WebAssembly Instantiation: Imports argument must be present and must be an object

I'm following this "hello world" tutorial: https://steemit.com/eos/@skenan/eos-development-for-beginners-webassembly

and I get this error:

TypeError: WebAssembly Instantiation: Imports argument must be present and must be an object

Any idea what might be causing it?

Upvotes: 12

Views: 16408

Answers (2)

SamChan
SamChan

Reputation: 91

The reason you got this error is probably because: when you initiate a webassembly instance, you need to specify the import object as well. Just like:

WebAssembly.instantiate(module, imports);

Well, here I'm just giving a simple example to demonstrate the steps:

    imports.env = imports.env || {}

    Object.assign(imports.env, {
      tableBase: module.tableBase,
      table: new WebAssembly.Table({
        initial: 4,
        element: 'anyfunc',
      }),
      print:function(msg){
        console.log(msg);
      }
    });
    return new WebAssembly.Instance(module, imports)

Upvotes: 4

Mauro Bringolf
Mauro Bringolf

Reputation: 538

I am not able to reproduce this error by following the tutorial. It works fine for me. Did you make any changes to the C source or JavaScript loading code?

The error you are seeing occurs if you instantiate a module without giving it all its required imports. But a module without imports like the one in the tutorial can be instantiated without an imports object. Documentation is here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate#Parameters.

Upvotes: 2

Related Questions