[bug] `--target bundler`: namespaced exports (`js_namespace`) are missing from the entry module's re-export list

Author: espgCreated Aug 9, 2026Updated Aug 9, 2026

Describe the bug

With js_namespace on an exported function (supported since 0.2.106, #4744), the bundler target generates the namespace object in index_bg.js but does not re-export it from the entry index.js, so the namespace is invisible to consumers importing the package. The web and nodejs targets handle the same code correctly.

Reproduction

wasm-bindgen 0.2.126, wasm-pack 0.15.0, rustc 1.97.1, node 23.5.0.

rust
use wasm_bindgen::prelude::*;

#[wasm_bindgen(js_namespace = testns, js_name = ping)]
pub fn test_ns_ping() -> u32 { 42 }
bash
wasm-pack build --out-name index --target bundler

pkg/index_bg.js (correct — lines 342-348 of our build):

javascript
function testns__ping() {
    const ret = wasm.testns__ping();
    return ret >>> 0;
}

export const testns = {};
testns.ping = testns__ping;

pkg/index.js — this is the complete file; testns appears nowhere in it (grep -c testns pkg/index.js → 0):

javascript
/* @ts-self-types="./index.d.ts" */
import * as wasm from "./index_bg.wasm";
import { __wbg_set_wasm } from "./index_bg.js";

__wbg_set_wasm(wasm);
wasm.__wbindgen_start();
export {
    Coordinate, EllipsoidInverseFlattening, EllipsoidSemiMinorAxis, Sphere, init_panic_hook, nested, parseEllipsoid, ring, zuniq
} from "./index_bg.js";

(The other names are the exports of the crate the probe was added to, GRID4EARTH/healpix-geo js/; the point is that the list is complete and testns is not in it.)

import { testns } from "pkg" therefore fails to resolve, even though pkg/index.d.ts declares it:

typescript
declare function testns__ping(): number;

export let testns: {
    ping: typeof testns__ping,
};

Expected

index.js should include testns in its re-export list, as the other two targets do for the same input:

  • --target nodejsindex.js:359: exports.testns = testns;
  • --target webindex.js:349: export const testns = {} in the single-file glue, i.e. directly in the entry.

Notes

  • Possibly related to "Ensure Node (CJS/ESM) and bundler entrypoints only expose public exports (no internal import shims)" (0.2.107) and to the js_namespace-on impl work in #5154 (0.2.122): the entry re-export list looks like it is built from classes and free functions only, with namespace objects never added to it.
  • Workaround we're using: emulate namespaces with unit structs (#[wasm_bindgen(js_name = ns)] pub struct Ns; + static methods), which works on all three targets.

Source: wasm-bindgen/wasm-bindgen