play-locally: importing a .wasm in a game server gives Node's instance exports, not a WebAssembly.Module
Bug
What I was doing: running a game server that imports a WebAssembly file, with npx @zaisma/cli play-locally.
Expected: the game server reference says import mod from "./physics.wasm" gives a WebAssembly.Module, which new WebAssembly.Instance(mod, imports) starts, and that the Node runner behaves the same as Zaisma's rooms.
What happened: on the local runner the import never gives a WebAssembly.Module. Node handles the .wasm file itself: it instantiates the module and hands back its exports.
- A module with no imports fails to load, because it has no export named
default:
[game server] The requested module './add.wasm' does not provide an export named 'default'
Your game server didn't start. Fix what it says above and save the file: it starts again by itself.- A module with imports (wasm-bindgen output, for example) fails earlier, because Node resolves each import's module name as a package:
Error [ERR_MODULE_NOT_FOUND]: Cannot find package '__wbindgen_externref_xform__' imported from …/zaisma-server/core.wasmTo make it happen again: a folder with an index.html and
// zaisma-server/index.js
import mod from "./add.wasm";
console.log("mod instanceof WebAssembly.Module:", mod instanceof WebAssembly.Module);
export default { setup: () => ({}) };where add.wasm is any valid module, such as one exporting a single add function. Then npx @zaisma/cli play-locally.
Cause, as far as I can tell: the runner loads the entry with a plain import() (bin/local-play-runner.js and bin/node.js), so .wasm files go through Node's own WebAssembly module support, which gives the instance, not the module.
Not checked: I haven't run the same server in Zaisma's rooms yet, so "gives a WebAssembly.Module there" is from the docs, not from a test. I also didn't try Node 22, the oldest the runner supports.
Workaround: build the server's WebAssembly with no imports at all, import the namespace, and accept either shape:
import * as coreFile from "./core.wasm";
const compiledModule = coreFile.default;
const coreExports = compiledModule instanceof WebAssembly.Module
? new WebAssembly.Instance(compiledModule, {}).exports
: coreFile;This only works for a module without imports, so it rules out wasm-bindgen and most physics engines' builds.
Suggestion: have the runner register a load hook for .wasm files inside the game server's folder that answers a module whose default export is new WebAssembly.Module(bytes), so the local runner matches the rooms.