wasmerio / wasmer-js

Monorepo for Javascript WebAssembly packages by Wasmer
https://wasmerio.github.io/wasmer-js/
MIT License
943 stars 83 forks source link

TypeError: Cannot read properties of undefined (reading 'wasmer_fromFile') #434

Closed ThatXliner closed 1 month ago

ThatXliner commented 1 month ago

Describe the bug

$ touch whatever.wasm
$ npm init
...
$ npm i @wasmer/sdk
...
# Create index.js
$ vim index.js
...
$ node index.js
TypeError: Cannot read properties of undefined (reading 'wasmer_fromFile')
    at u_.fromFile (file:///Users/bryanhu/projects/Experiments/Ayu/node_modules/@wasmer/sdk/dist/index.mjs:11:21439)
    at runWasm (file:///Users/bryanhu/projects/Experiments/Ayu/index.node.js:9:31)
// index.js
import { Wasmer } from "@wasmer/sdk";
import { promises as fs } from "fs";

async function runWasm() {
  // Read the WASM file
  const wasmBytes = await fs.readFile("whatever.wasm");

  // Instantiate the Wasmer module
  const cowsay = await Wasmer.fromFile(wasmBytes);

  // Run the entrypoint with the given arguments
  const instance = await cowsay.entrypoint.run({
    args: '"Hello world"',
  });

  // Wait for the instance to complete and get the output
  const output = await instance.wait();

  console.log(output);
}

runWasm().catch(console.error);
wasmer 4.3.7 (c6c348d 2024-09-09)
binary: wasmer-cli
commit-hash: c6c348d00fa3582eb3b3fda07e69fdc695156193
commit-date: 2024-09-09
host: aarch64-apple-darwin
compiler: singlepass,cranelift
rustc 1.81.0 (eeb90cda1 2024-09-04)
binary: rustc
commit-hash: eeb90cda1969383f56a2637cbd3037bdf598841c
commit-date: 2024-09-04
host: aarch64-apple-darwin
release: 1.81.0
LLVM version: 18.1.7

Steps to reproduce

Expected behavior

Actual behavior

Additional context

ThatXliner commented 1 month ago

Ok so I guess you have to run await init(). But now I'm getting

error: Unable to detect the WEBC version
syrusakbary commented 1 month ago

Hey, fromFile is for Wasmer packages, not wasm files. I think we can probably add support for running wasm files when using fromFile

ThatXliner commented 1 month ago

Thanks. I also realized my use-case is the original intended use for WASM so I don’t necessarily need Wasmer (unless… smth smth WASIX).