WASM: IDBFS not exported to runtime under Emscripten 5.0.0 — /save mount throws ReferenceError #385

Closed
opened 2026-07-16 04:42:02 +00:00 by john · 0 comments
Owner

Symptom

Loading any WASM build (playground or shipped game) throws at startup:

Uncaught (in promise) ReferenceError: IDBFS is not defined
    preRun .../playground/#...

Root cause

Both src/shell.html and src/shell_game.html mount IDBFS at /save/ in
Module.preRun for persistent game data:

FS.mkdir('/save');
FS.mount(IDBFS, {}, '/save');

The IDBFS implementation is linked in (-lidbfs.js in CMakeLists.txt), but
EXPORTED_RUNTIME_METHODS only listed ccall,cwrap,FSIDBFS was
missing
. Bare FS works in preRun because it is exported; bare IDBFS was
not, so it never reached the shell scope.

Older Emscripten auto-exposed IDBFS; Emscripten 5.0.0 stopped doing so,
which is why this only surfaced on a fresh rebuild — the previously-deployed
playground was built with an older SDK.

Fix

Add IDBFS to the shared Emscripten link flags in CMakeLists.txt:

-sEXPORTED_RUNTIME_METHODS=ccall,cwrap,FS,IDBFS

Verified: the rebuilt glue JS now contains Module["IDBFS"]=IDBFS (absent
before), and the /save mount no longer throws. The flag block is shared across
all Emscripten targets, so playground and game builds are fixed.

Follow-up

The shipped 0.2.8 WASM.zip game predates this and should be rebuilt before
the web game is relied upon (it would hit the same crash if built under
Emscripten 5.0.0).

## Symptom Loading any WASM build (playground or shipped game) throws at startup: ``` Uncaught (in promise) ReferenceError: IDBFS is not defined preRun .../playground/#... ``` ## Root cause Both `src/shell.html` and `src/shell_game.html` mount IDBFS at `/save/` in `Module.preRun` for persistent game data: ```js FS.mkdir('/save'); FS.mount(IDBFS, {}, '/save'); ``` The IDBFS *implementation* is linked in (`-lidbfs.js` in `CMakeLists.txt`), but `EXPORTED_RUNTIME_METHODS` only listed `ccall,cwrap,FS` — **`IDBFS` was missing**. Bare `FS` works in `preRun` because it is exported; bare `IDBFS` was not, so it never reached the shell scope. Older Emscripten auto-exposed `IDBFS`; **Emscripten 5.0.0 stopped doing so**, which is why this only surfaced on a fresh rebuild — the previously-deployed playground was built with an older SDK. ## Fix Add `IDBFS` to the shared Emscripten link flags in `CMakeLists.txt`: ``` -sEXPORTED_RUNTIME_METHODS=ccall,cwrap,FS,IDBFS ``` Verified: the rebuilt glue JS now contains `Module["IDBFS"]=IDBFS` (absent before), and the `/save` mount no longer throws. The flag block is shared across all Emscripten targets, so playground **and** game builds are fixed. ## Follow-up The shipped `0.2.8` `WASM.zip` game predates this and should be rebuilt before the web game is relied upon (it would hit the same crash if built under Emscripten 5.0.0).
john closed this issue 2026-07-16 04:42:52 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
john/McRogueFace#385
No description provided.