I am trying to run a game I built with Bevy and Rust in the browser. Bevy started supporting WebGL2 from version 0.11.0, and I am using this version. I have compiled my Rust code to WebAssembly using wasm-pack build --target web
.
However, when I try to initialize the WebAssembly module in my HTML file, I get the following error:
WebAssembly.instantiate(): Import #0 module="__wbindgen_placeholder__" error: module is not an object or function
Here is the JavaScript code I am using to initialize the WebAssembly module:
import init, { run } from './game.js';
async function main() {
await init('./game.wasm');
run();
}
main();
In main.rs I have my run function with the export defined like:
#[wasm_bindgen]
pub fn run() {
App::new()
.add_plugins(DefaultPlugins)
//initialize more systems and resources
}
I have verified my paths are correct, and I am serving the files using the Live Server extension in VSCode. I am using the latest version of chrome and rust on popOS.
I have also checked the Bevy documentation and examples, but I couldn't find any specific guidance on this issue.
Does anyone know what could be causing this error and how to fix it?