ceifa / wasmoon

A real lua 5.4 VM with JS bindings made with webassembly
MIT License
480 stars 31 forks source link

Failed to initialize LuaFactory in Vercel with custom wasm file path. #118

Open pureliumy opened 3 months ago

pureliumy commented 3 months ago

Problem Failed to initialize LuaFactory in Vercel with custom wasm file path.

Demo code

// This way we could load the wasm file in Vercel production environment.
const luaWasmFile = path.resolve('public/lib/glue.wasm');
const factory = new LuaFactory(luaWasmFile);

Error output

failed to asynchronously prepare wasm: TypeError: WebAssembly.instantiate(): Import #0 module="env" error: module is not an object or function

Remarks I don't know whether it is related to the file import method or not, but I have tried many ways, only the above way worked in Vercel production environment.

/**
 * These didn't work in Vercel production environment, luaWasmFile will be not found.
 * 
 * 1. https://vercel.com/docs/functions/wasm
 * 2. https://github.com/Drumsin/aoe4-generated-map-debugger/pull/6/files
 */

import luaWasmFile from 'wasmoon/dist/glue.wasm';
const factory = new LuaFactory(luaWasmFile);
pureliumy commented 3 months ago

I tried using a custom build wasmoon dist/index.js and glue.wasm, this error disappeared, but there was a new error when executed await factory.createEngine() - e is not a function.

I have no idea with what e is as the code was minified.