windmill-labs/windmill · error
eval_sync is only available in wasm32
Error message
eval_sync is only available in wasm32
What it means
`eval_sync` in windmill-parser-ts only exists when compiled for `wasm32`; the non-wasm fallback is a hard `panic!`. Code calling `eval_sync` outside the WASM runtime (e.g. unit tests or native builds of the TS parser crate) aborts, because JS evaluation depends on the browser/wasm bindgen `eval` function.
Source
Thrown at backend/parsers/windmill-parser-ts/src/lib.rs:1263
#[cfg(target_arch = "wasm32")]
#[wasm_bindgen]
extern "C" {
pub fn eval(s: &str) -> JsValue;
pub fn alert(s: &str);
#[wasm_bindgen(js_namespace = console)]
fn log(s: &str);
}
#[cfg(target_arch = "wasm32")]
pub fn eval_sync(code: &str) -> Result<serde_json::Value, String> {
serde_wasm_bindgen::from_value(eval(format!("let x = {}; x", code).as_str()))
.map_err(|err| format!("Cannot deserialize value: {:?}", err))
}
#[cfg(not(target_arch = "wasm32"))]
pub fn eval_sync(_code: &str) -> Result<serde_json::Value, String> {
panic!("eval_sync is only available in wasm32")
}
View on GitHub (pinned to e474e8803c)
Solutions
- Run the code inside the wasm32 target (the intended deployment: compile to WASM and call from JS)
- Gate the test/caller with #[cfg(target_arch = "wasm32")] so it is skipped on native builds
- Refactor the caller to accept a pre-computed value instead of evaluating JS synchronously on native targets
Example fix
// before
#[test]
fn evals() { assert_eq!(eval_sync("1+1").unwrap(), 2); }
// after
#[cfg(target_arch = "wasm32")]
#[test]
fn evals() { assert_eq!(eval_sync("1+1").unwrap(), 2); } Defensive patterns
Strategy: type-guard
Validate before calling
// Rust caller: only call eval_sync on wasm builds
#[cfg(target_arch = "wasm32")]
let v = eval_sync(code)?;
#[cfg(not(target_arch = "wasm32"))]
let v: serde_json::Value = return Err("eval_sync requires the wasm32 parser build".into()); Type guard
fn eval_sync_available() -> bool {
cfg!(target_arch = "wasm32")
}
// guard: if !eval_sync_available() { skip/defer the eval path } Try / catch
std::panic::catch_unwind(|| eval_sync(code)).unwrap_or_else(|_|
Err("eval_sync is only available in wasm32; use the wasm build of windmill-parser-ts".to_string())) Prevention
- Never call eval_sync from native tests or native binaries
- Gate eval-dependent tests with #[cfg(target_arch = "wasm32")]
- Run parser tests via wasm-bindgen-test instead of cargo test natively
When it happens
Trigger: Calling `eval_sync` from a build without `target_arch = "wasm32"` — typically native unit tests, CLI tooling, or a non-wasm consumer of the parser crate.
Common situations: Running the parser crate's tests natively with a test that hits eval_sync; embedding windmill-parser-ts in a native Rust binary instead of the WASM module.
Related errors
- Aborted from C
- fputs is not supported
- fputc is not supported
- fdopen is not supported
- fclose is not supported
AI-assisted analysis of windmill-labs/windmill@e474e8803c (2026-09-03).
Data as JSON: /api/errors/09edd0e18e356cee.
Report an issue: GitHub.