Skip to content

2D cores and CLI toolchains ship node-only glue, so romdev-core-host's browser path can't load them #7

Open

Description

@deviankim

romdev-core-host documents a browser / bytes-only path:

import factory from "romdev-core-fceumm/wasm/fceumm_libretro.js";
await host.loadCore({ factory, wasmBinary, io: false });

but the published glue can't run outside Node. Every 2D libretro core and every tool linked with EM_CLI_FLAGS in scripts/_lib.sh (sdcc/sdas*/sdld, mcpp, rgbds, cc65, asar, dasm, tcc816, wla-dx, vasm) is built with -s ENVIRONMENT=node, so emcc hard-codes

var ENVIRONMENT_IS_WEB = false;
var ENVIRONMENT_IS_WORKER = false;
var ENVIRONMENT_IS_NODE = true;
if (ENVIRONMENT_IS_NODE) { const { createRequire } = await import('module'); ... }

and loading romdev-core-gambatte@0.12.1's gambatte_libretro.js (or romdev-toolchain-sdcc@0.2.2's sdcc.js) in a page or a module Web Worker fails on import("module") before the wasm is instantiated. Nothing in these cores or tools needs Node — they only use MEMFS — and the GPU cores (flycast, beetle-psx-hw, parallel-n64) already link with ENVIRONMENT=node,web.

Repro (Chrome, static server, files copied from romdev-core-gambatte@0.12.1/wasm/):

<script type="module">
  const { default: factory } = await import("./gambatte_libretro.js");
  const wasmBinary = new Uint8Array(await (await fetch("./gambatte_libretro.wasm")).arrayBuffer());
  await factory({ wasmBinary });
</script>

→ TypeError: Failed to resolve module specifier 'module'. The same page with the glue relinked with -s ENVIRONMENT=node,web,worker (same recipe, emscripten 4.0.18 image) loads fine — and the rebuilt gambatte_libretro.wasm is byte-identical to the published one; only the glue changes.

Workaround I'm using today: rewrite var ENVIRONMENT_IS_NODE=true → false in the glue after install. With that one flag flipped, gambatte + the SDCC sm83 pipeline run fine in a Web Worker (built and played GB/GBC ROMs in the browser), which suggests the right fix is just the link flag.

Proposal: link these recipes with -s ENVIRONMENT=node,web,worker. Runtime detection keeps picking node under Node, so the server is unaffected, and the .wasm output doesn't change (only the JS glue). A guard in scripts/verify-wasm.mjs could keep them from regressing at publish time. I have a PR ready for this.

Activity

  1. deviankim commented on Oct 29, 2026

    @deviankim
    Author

    Update: I closed #8, it had grown well past this issue. #15 is a fresh PR against current main with only this change.

    Since I opened this, vasm is gone from main, so it is out of the list, and bsnes is new and gets the same flag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions