Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't work in browser #293

Closed
Gbr22 opened this issue May 28, 2022 · 4 comments
Closed

Doesn't work in browser #293

Gbr22 opened this issue May 28, 2022 · 4 comments

Comments

@Gbr22
Copy link

Gbr22 commented May 28, 2022

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:
image

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)
@Gbr22
Copy link
Author

Gbr22 commented May 28, 2022

Update: It seems to work in firefox

@Gbr22
Copy link
Author

Gbr22 commented May 28, 2022

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:
image

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

@Gbr22 Gbr22 changed the title Doesn't work with vite Doesn't work in browser May 28, 2022
@Gbr22 Gbr22 closed this as completed May 28, 2022
@corwin-of-amber
Copy link
Contributor

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.

@X7md
Copy link

X7md commented Jul 15, 2022

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: image

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants