admin管理员组文章数量:1395889
I'm trying to instantiate a .wasm file locally in node.js. The goal is to run the binary locally and reproduce the functionalities of the web page. Here's my minimum reproducible example:
const fetch = require("node-fetch");
const importObject = {
imports: {
imported_func: function(arg) {
console.log(arg);
}
}
};
fetch('.wasm').then(response =>
response.arrayBuffer()
).then(bytes => {
let mod = new WebAssembly.Module(bytes);
let instance = new WebAssembly.Instance(mod, importObject);
instance.exports.exported_func();
})
The error I get is:
TypeError: WebAssembly.Instance(): Import #0 module="wasi_unstable" error: module is not an object or function
I saw some questions with similar problems but no real solutions were provided. This is my first time working with wasm so I'm pretty lost.
I'm trying to instantiate a .wasm file locally in node.js. The goal is to run the binary locally and reproduce the functionalities of the web page. Here's my minimum reproducible example:
const fetch = require("node-fetch");
const importObject = {
imports: {
imported_func: function(arg) {
console.log(arg);
}
}
};
fetch('https://www.supremenewyork./ticket.wasm').then(response =>
response.arrayBuffer()
).then(bytes => {
let mod = new WebAssembly.Module(bytes);
let instance = new WebAssembly.Instance(mod, importObject);
instance.exports.exported_func();
})
The error I get is:
TypeError: WebAssembly.Instance(): Import #0 module="wasi_unstable" error: module is not an object or function
I saw some questions with similar problems but no real solutions were provided. This is my first time working with wasm so I'm pretty lost.
Share Improve this question edited Oct 2, 2022 at 0:58 Heretic Monkey 12.1k7 gold badges61 silver badges131 bronze badges asked Jun 4, 2020 at 12:11 Lucca BaumgärtnerLucca Baumgärtner 2071 gold badge3 silver badges8 bronze badges3 Answers
Reset to default 3Your module seems to depend on the wasi_unstable
API. If you want to load it you will need an implementation of that API.
To see exactly what imports you module needs you can use wasm2wat
or wasmdis
tools from wabt and binaryen projects respectively.
If you built your wasm module with emscripten then the remended practice is to have the emscripten generate JS to that implenents these APIs and takes case of loading the module for you.
If you build your wasm module with the wasi-sdk then you need some kind of web polyfill for the WASI APIs.
This will make the error go away:
const importObject = {
imports: {
imported_func: function(arg) {
console.log(arg);
},
wasi_unstable: () => {}
}
};
Try this one
const importObject = {
wasi_unstable: {
imported_func: function(args) {
console.log(args);
}
}
};
本文标签: javascriptError instantiating WASM module quotmodule is not an object or functionquotStack Overflow
版权声明:本文标题:javascript - Error instantiating WASM module: "module is not an object or function" - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744088072a2588905.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论