wasmerio / wasmer

🚀 The leading Wasm Runtime supporting WASIX, WASI and Emscripten
https://wasmer.io
MIT License
18.48k stars 789 forks source link

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

Open ThatXliner opened 6 hours ago

ThatXliner commented 6 hours 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 4 hours ago

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

error: Unable to detect the WEBC version