-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: Wasm bindgen incompatibility with Node 22 #2254
Comments
I tried to reproduce it, but for me it actually works
|
says it pulled Edit: my bad, I have it set to node:21 in the reproduction |
So yes after changing it to 22 it also fails for me, couldn't figure out what exactly causes this yet, but I found some additional info that might help const { Client, initLogger } = require("@iota/sdk-wasm/node");
(async () => {
try {
initLogger()
const client = new Client({ primaryNode: "https://api.testnet.shimmer.network/" });
// Works
console.log(await client.getInfo());
// Works
console.log(await client.getOutput("0x0e67475116d5e5a0c845c8f89bb15e3b9f7059001e8e674443d45d153c921bf90000"));
// Fails
console.log(await client.getOutput("0x9e190f35188fa7986205a8fed2dd69554d7a3218805709ee04cc73a87bc9cd090000"));
// Also fails
console.log(await client.getBlock("0xee4936315c60809a48665b7b85225788c4c56abad46147ab3483e1fc499213a1"));
} catch (error) {
console.log(error)
}
})(); Logs for output where it works and the one that doesn't work:
We should try reqwest in wasm alone next, probably the issue happens without iota-sdk and large bodies |
Did some more testing and could reproduce it with reqwest alone seanmonstar/reqwest#2338 Cargo.toml [workspace]
[package]
name = "reqwest-wasm"
version = "0.1.0"
edition = "2021"
[lib]
crate-type = ["cdylib", "rlib"]
[dependencies]
js-sys = { version = "0.3.68", default-features = false, features = [] }
serde_json = { version = "1.0.113", default-features = false }
reqwest = { version = "0.11.24", default-features = false, features = [
"json",
]}
wasm-bindgen = { version = "0.2.92", default-features = false, features = [
"std",
"serde-serialize",
] }
wasm-bindgen-futures = { version = "0.4.41", default-features = false } lib.rs use wasm_bindgen::{prelude::wasm_bindgen, JsCast, JsValue};
use wasm_bindgen_futures::future_to_promise;
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(typescript_type = "Promise<string>")]
pub type PromiseString;
}
#[wasm_bindgen(js_name = bytes)]
pub fn bytes(url: String) -> Result<PromiseString, JsValue> {
let promise: js_sys::Promise = future_to_promise(async move {
let resp = reqwest::Client::new().get(url)
.send()
.await
.map_err(|err| err.to_string())?;
Ok(JsValue::from(format!("bytes: {:?}", &resp.bytes().await.map_err(|err| err.to_string())?)
))
});
Ok(promise.unchecked_into())
}
#[wasm_bindgen(js_name = works)]
pub fn works(url: String) -> Result<PromiseString, JsValue> {
let promise: js_sys::Promise = future_to_promise(async move {
let resp = reqwest::Client::new().get(url)
.send()
.await
.map_err(|err| err.to_string())?;
let resp_str: serde_json::Value = serde_json::from_str(
&resp.text().await.map_err(|err| err.to_string())?,
).unwrap();
Ok(JsValue::from(format!("works: {}", serde_json::to_string(
&resp_str,
).unwrap())
))
});
Ok(promise.unchecked_into())
}
#[wasm_bindgen(js_name = fails)]
pub fn fails(url: String) -> Result<PromiseString, JsValue> {
let promise: js_sys::Promise = future_to_promise(async move {
let resp = reqwest::Client::new().get(url)
.send()
.await
.map_err(|err| err.to_string())?;
Ok(JsValue::from(format!("doesn't work with large data: {:?}", &resp.json::<serde_json::Value>().await.map_err(|err| err.to_string())?)))
});
Ok(promise.unchecked_into())
} index.js
|
Issue description
API calls via the Wasm bindings fail in Node 22 environments (docker and local)
Node 21 (via
node:21
image) worksVersion
1.1.3
Expected behaviour
return JSON API response
Actual behaviour
return error
Can the issue reliably be reproduced?
Yes
Steps to reproduce the issue
Find instructions and code for reproduction in docker here:
https://github.com/eike-hass/iota-sdk/tree/bug/network-error-in-dockerized-node22/bindings/wasm/reproduction
Or use local Node 22 and run
node index.js
in reproduction folderErrors
-> % docker run repro
Duplicate declaration
The text was updated successfully, but these errors were encountered: