jsonwebtoken icon indicating copy to clipboard operation
jsonwebtoken copied to clipboard

JS calls brought in for every compile for WASM

Open ranile opened this issue 6 months ago • 0 comments

When compiling for wasm, the only option is to bring in JS bindings for web APIs. However, wasm is used a for a lot more than just browsers or runtime with web APIs available, causing this library to be unusable in those cases.

One such example is https://forum.dfinity.org/t/module-imports-function-wbg-now-2e07eedfb4ac9dbe-from-wbindgen-placeholder-that-is-not-exported-by-the-runtime/22083, with me also running into the same issue.

Culprit code

https://github.com/Keats/jsonwebtoken/blob/5cd1887848f7d30f11adb4ebcec6a01baffd5252/Cargo.toml#L30-L35

Solution

Give option to opt out of JS calls on wasm targets. One way to do that is to move JS calls behind a feature flag, similar to the ring crate that is enabled here. Note that wasm32-unknown-unknown target is not enough to assume that JS API will be available, as is the case for the platform of the forum post linked above

ranile avatar Jun 20 '25 12:06 ranile