Skip to content
This repository has been archived by the owner on Jun 13, 2023. It is now read-only.

@wasmer/wasi: Document Demo Fail #152

Closed
sinoon opened this issue Apr 13, 2022 · 4 comments
Closed

@wasmer/wasi: Document Demo Fail #152

sinoon opened this issue Apr 13, 2022 · 4 comments
Assignees

Comments

@sinoon
Copy link

sinoon commented Apr 13, 2022

The Demo in : https://docs.wasmer.io/integrations/js/reference-api/wasmer-wasi

const browserBindings = require("@wasmer/wasi/lib/bindings/browser");
// for Node:
// const nodeBindings = require("@wasmer/wasi/lib/bindings/node");

// omit other part

That has am error: Cannot resolve dependency '@wasmer/wasi/lib/bindings/browser

image

After look inside, @wasmer/wasi "@wasmer/wasi": "^0.10.0" has directory lib in npm module, but the latest version does't.

So, the question is, is there the way run wasi in browser?

@nicobytes
Copy link

nicobytes commented Apr 28, 2022

I have the same problem. I tried to follow the official example in the docs, but it shows an error:

 Failed to resolve '@wasmer/wasi/lib/bindings/browser' from './src/index.js'

image

Then try to run the official example for Nodejs, like this:

import fs from "fs";
import { init, WASI } from "@wasmer/wasi";

// This is needed to load the WASI library first
await init();

let wasi = new WASI({
  env: {},
  args: [],
});

const buf = fs.readFileSync('./src/demo.wasm');

const module = await WebAssembly.compile(
  new Uint8Array(buf)
);
await wasi.instantiate(module, {});

let exitCode = wasi.start();
let stdout = wasi.getStdoutString();
// This should print "hello world (exit code: 0)"
console.log(`${stdout}(exit code: ${exitCode})`);

NodeJS works, but in the browser doesn't work, I tried adjusting the NodeJS example to browser using fetch, like this:

import { init, WASI } from "@wasmer/wasi";

await init();

let wasi = new WASI({
  env: {},
  args: [],
});

let response  = await fetch('/demo.wasm');
let wasmBytes = new Uint8Array(await response.arrayBuffer());

const module = await WebAssembly.compile(wasmBytes);
await wasi.instantiate(module, {});

let exitCode = wasi.start();
let stdout = wasi.getStdoutString();
// This should print "hello world (exit code: 0)"
console.log(`${stdout}(exit code: ${exitCode})`);

But it shows the following error:

 Failed to resolve 'wasmer_wasi_js_bg.wasm' from './node_modules/@wasmer/wasi/dist/Library.esm.min.js'

image

@c4lliope
Copy link

c4lliope commented May 2, 2022

The missing wasmer_wasi_js_bg.wasm can be marked as an "external" if you are compiling using webpack.
The error has already been discussed in wasmerio/wasmer-js#290.

@corwin-of-amber
Copy link

The outdated reference to @wasmer/wasi/lib/bindings/browser in the documentation as pointed out by @sinoon and @nicobytes is a hinderance. Can you please remove it?

Also probably should add a note about the external config which is required for Webpack users.

@syrusakbary
Copy link
Member

We have published a new version of @wasmer/wasi which no longer has the issue I believe. I'll work on updating the wasmer docs :)

@syrusakbary syrusakbary transferred this issue from wasmerio/wasmer-js Aug 31, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants