问题
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?
Thanks!
回答1:
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)
回答2:
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.
来源:https://stackoverflow.com/questions/49635240/typeerror-webassembly-instantiation-imports-argument-must-be-present-and-must