Troubleshooting
The browser fails to load .wasm with 404/incorrect MIME type
- Vite copies
.wasmto thedistwhenassetsIncludeincludes**/*.wasm. When you serve the built app, ensure the files were published and thebaseinvite.config.jsis correct (this repo uses/Img2Num/).
Hot reload doesn't pick up changes
- Confirm the plugin added the files to
server.watcher. If not, openvite.config.jsand verifyfg.sync('src/wasm/**/*.{cpp,h}')returns your files. - Ensure the watcher is not ignoring the paths (see
server.watch.ignoredinvite.config.js).
Large .wasm size
- Use
-O3with--closure 1or-Osdepending on your performance/size tradeoffs. - Strip debug symbols for production builds (
-s DEMANGLE_SUPPORT=0and remove-g). - Use
-s ALLOW_MEMORY_GROWTH=1only if necessary; fixed memory can be slightly smaller. - Audit exported functions — export only what you need via
EXPORTED_FUNCTIONSorEMSCRIPTEN_BINDINGS.
Optimizations checklist
- Build release with
-O3and closure compiler. Example flag additions:emcc ... \
-O3 \
--closure 1 \
-s ALLOW_MEMORY_GROWTH=0 \
-s MODULARIZE=1 \
-s EXPORT_NAME="createModule" - Use
MODULARIZEandEXPORT_NAMEto control loader behavior and reduce global pollution. - Use lazy instantiation: only instantiate the WASM module in components that need it.
- Consider splitting functionality into multiple modules to avoid shipping large monolithic WASM files.
CI & reproducible builds
- In CI, install a pinned emsdk version and call
npm run build-wasm(ormake -C src/wasm build). - Cache the emsdk install between CI runs to save time.
If builds hang or fail on Windows
- Run builds inside WSL2 or use a cross-platform Docker image that has emsdk preinstalled.