bytecodealliance / bytecodealliance/wasmtime

Wasmtime tutorial is incorrect: Import #0 module="wasi_snapshot_preview1" error: module is not an object or function

Open
#2,968 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
18.6k
Forks
1.8k
Avg merge
1d 18h
Merged PRs (30d)
126

Description

After following the wasmtime tutorial https://github.com/bytecodealliance/wasmtime/blob/main/docs/WASI-tutorial.md I am unable to run the resulting output in the polyfill site.

The site errors with `Import #0 module="wasi_snapshot_preview1" error: module is not an object or function`

I have compiled the rust example in the tutorial, and even dumbed it down slighty so that it doesnt require CLI arguments. Here is my code.

```rust
use std::fs;
use std::io::{Write, self};

fn process(input_str: &str, output_fname: &str) -> Result<(), String> {

let mut output_file = fs::File::create(output_fname)
.map_err(|err| format!("error opening output {}: {}", output_fname, err))?;
output_file
.write_all(input_str.as_bytes())
.map_err(|err| format!("write error: {}", err))
}

fn main() -> io::Result<()> {
if let Err(err) = process(&"Hello World", &"tmp/file.txt") {
eprintln!("{}", err)
}

io::stdout().write_all(b"done writing")?;
Ok(())
}

```

I have confirmed that this code runs as expected in the wasmtime cli

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.