Doesn't work in browser
Gbr22 opened this issue · comments
Here is my code:
import { Buffer } from 'buffer'
window.Buffer = Buffer;
import { init, WASI } from '@wasmer/wasi';
await init();
let wasi = new WASI({
env: {
// 'ENVVAR1': '1',
// 'ENVVAR2': '2'
},
args: [
'command', 'arg1', 'arg2'
],
});
async function wasiTest(){
const moduleBytes = fetch("/cowsay.wasm");
const module = await WebAssembly.compileStreaming(moduleBytes);
// Instantiate the WASI module
await wasi.instantiate(module, {});
// Run the start function
let exitCode = wasi.start();
let stdout = wasi.getStdoutString();
// This should print "hello world (exit code: 0)"
console.log(`${stdout}(exit code: ${exitCode})`);
}
When I call wasiTest I get the following error:
Uncaught (in promise) Error: Failed to instantiate WASI: RuntimeError: `
at B2.wbg.__wbg_new_342a24ca698edd87 (Library.esm.min.js:25:11051)
at 0024ee5a:0x7c9d3
at 0024ee5a:0x19d5a
at s.instantiate (Library.esm.min.js:25:6746)
at wasiTest (GlobalState.js?t=1653754911321:26:16)
Update: It seems to work in firefox
TLDR: Move your code to a worker thread
I figured it out
I found a similar issue to mine: #286 (comment)
Which led me to this issue: #302
I downloaded and built HarukaMa's version and it threw this error message:
Then I moved my code into a worker and it magically worked. Turns out there's no issue with the library after all it's just that it fails to give a helpful error message that I have to use workers
I would comment that the loss of the original error string is a bug. It even looks like something was supposed to be there: there is an extra tick after RuntimeError:
. WDYT, can someone look at the code throwing the error perhaps? Might be a simple typo.
TLDR: Move your code to a worker thread
I figured it out
I found a similar issue to mine: #286 (comment)
Which led me to this issue: wasmerio/wasmer-js#302 (comment)
I downloaded and built HarukaMa's version and it threw this error message:
Then I moved my code into a worker and it magically worked. Turns out there's no issue with the library after all it's just that it fails to give a helpful error message that I have to use workers
Could you put any example or code snippet, about how you actually move it to Worker
?