# @bjorn3/browser_wasi_shim

> A pure javascript shim for WASI

Latest version **0.4.2** (published 2025-06-22) · MIT OR Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @bjorn3/browser_wasi_shim
pnpm add @bjorn3/browser_wasi_shim
yarn add @bjorn3/browser_wasi_shim
bun add @bjorn3/browser_wasi_shim
```

## Health

**Score 50/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 0.4.2 |
| Published | 2025-06-22 |
| First published | 2022-08-11 |
| Weekly downloads | 0 |
| License | MIT OR Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 111.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 430 |
| Author | bjorn3 |
| Maintainers | bjorn3 |

## Links

- npm: https://www.npmjs.com/package/@bjorn3/browser_wasi_shim
- Repository: https://github.com/bjorn3/browser_wasi_shim
- Homepage: https://github.com/bjorn3/browser_wasi_shim#readme
- Issues: https://github.com/bjorn3/browser_wasi_shim/issues
- npm.io page: https://npm.io/package/@bjorn3/browser_wasi_shim

## Recent versions

- 0.4.2 (latest) — 2025-06-22
- 0.4.1 — 2025-02-13
- 0.4.0 — 2025-01-23
- 0.3.0 — 2024-04-11
- 0.2.21 — 2024-04-08
- 0.2.20 — 2024-03-11
- 0.2.19 — 2024-01-20
- 0.2.18 — 2024-01-11
- 0.2.17 — 2023-12-14
- 0.2.16 — 2023-11-14
- 0.2.15 — 2023-09-05
- 0.2.14 — 2023-06-13
- 0.2.13 — 2023-06-10
- 0.2.12 — 2023-06-09
- 0.2.11 — 2023-06-07
- … 12 more at https://npm.io/package/@bjorn3/browser_wasi_shim/versions

## README

# A pure javascript shim for WASI

Implementation status: A subset of wasi_snapshot_preview1 is implemented. The rest either throws an exception, returns an error or is incorrectly implemented.

## Usage

```
npm install @bjorn3/browser_wasi_shim --save
```

```javascript
import { WASI, File, OpenFile, ConsoleStdout, PreopenDirectory } from "@bjorn3/browser_wasi_shim";

let args = ["bin", "arg1", "arg2"];
let env = ["FOO=bar"];
let fds = [
    new OpenFile(new File([])), // stdin
    ConsoleStdout.lineBuffered(msg => console.log(`[WASI stdout] ${msg}`)),
    ConsoleStdout.lineBuffered(msg => console.warn(`[WASI stderr] ${msg}`)),
    new PreopenDirectory(".", [
        ["example.c", new File(new TextEncoder("utf-8").encode(`#include "a"`))],
        ["hello.rs", new File(new TextEncoder("utf-8").encode(`fn main() { println!("Hello World!"); }`))],
    ]),
];
let wasi = new WASI(args, env, fds);

let wasm = await WebAssembly.compileStreaming(fetch("bin.wasm"));
let inst = await WebAssembly.instantiate(wasm, {
    "wasi_snapshot_preview1": wasi.wasiImport,
});
wasi.start(inst);
```

## Building

```
$ npm install
$ npm run build
```

## Running the demo

The demo requires the wasm rustc artifacts and the xterm js package. To get them run:

```
$ git submodule update --init
$ cd examples && npm install
```

Run the demo with a static web server from the root of this project:

```
$ npx http-server
```

And visit [http://127.0.0.1:8080/examples/rustc.html]() in your browser.

A more complete demo by [@LyonSyonII](https://github.com/LyonSyonII) which runs
miri inside the browser can be found at <https://garriga.dev/rubri/>. (source
at <https://github.com/LyonSyonII/rubri>)

## Testing

```
$ python3 -m pip install -r ./test/wasi-testsuite/test-runner/requirements.txt
$ npm test
```

## License

Licensed under either of

  * Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or
    http://www.apache.org/licenses/LICENSE-2.0)
  * MIT license ([LICENSE-MIT](LICENSE-MIT) or
    http://opensource.org/licenses/MIT)

at your option.

### Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in the work by you shall be dual licensed as above, without any
additional terms or conditions.

---
_Source: https://npm.io/package/@bjorn3/browser_wasi_shim · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
