httpteapot
httpteapot3w ago

Error when calling a bun script using `wmill.runScript`

I have a bun script, that uses jsdom as a dependency. The script is working as expected when calling it directly through the windmill cloud UI. But now I try to create a second script, written in TS, and call the first script using
import * as wmill from "windmill-client"

export async function main() {
return await wmill.runScript('f/phones/myfirstscript', null, { pageToScrap: "https://example.com"})
}
import * as wmill from "windmill-client"

export async function main() {
return await wmill.runScript('f/phones/myfirstscript', null, { pageToScrap: "https://example.com"})
}
And this time I get the following error:
Error: Job 0192002f-4ee9-00ad-7389-62022edcd325 was not successful: {"name":"ExecutionErr","message":"ExitCode: 1, last log lines:\njob=0192002f-4ee9-00ad-7389-62022edcd325 tag=bun worker=wk-default-cj8jl-BuC5V hostname=windmill-workers-7f68684c68-cj8jl\n\nloaded bin/bundle from object store /tmp/windmill/cache/bun/9d943d25e4998b10a15907558fdc194673bf0d25764692290d7df612dabbd1bd in 115ms\n\n--- BUN BUNDLE SNAPSHOT EXECUTION ---\n\nerror: Cannot find module \"/tmp/windmill/wk-default-ncp74-Ke4NK/0192002e-bc76-62ce-853a-3f8a961048ff/node_modules/jsdom/lib/jsdom/living/xhr/xhr-sync-worker.js\" from \"/tmp/bun/main.js\"\n\nBun v1.1.27 (Linux arm64)"}
Error: Job 0192002f-4ee9-00ad-7389-62022edcd325 was not successful: {"name":"ExecutionErr","message":"ExitCode: 1, last log lines:\njob=0192002f-4ee9-00ad-7389-62022edcd325 tag=bun worker=wk-default-cj8jl-BuC5V hostname=windmill-workers-7f68684c68-cj8jl\n\nloaded bin/bundle from object store /tmp/windmill/cache/bun/9d943d25e4998b10a15907558fdc194673bf0d25764692290d7df612dabbd1bd in 115ms\n\n--- BUN BUNDLE SNAPSHOT EXECUTION ---\n\nerror: Cannot find module \"/tmp/windmill/wk-default-ncp74-Ke4NK/0192002e-bc76-62ce-853a-3f8a961048ff/node_modules/jsdom/lib/jsdom/living/xhr/xhr-sync-worker.js\" from \"/tmp/bun/main.js\"\n\nBun v1.1.27 (Linux arm64)"}
It seems related to the usage of jsdom in bun but it only occurs when calling a script using wmill.runScript and not when calling it directly.
14 Replies
rubenf
rubenf3w ago
@httpteapot UI and api uses absolutely exactly the same logic as they both use the api
httpteapot
httpteapot3w ago
I can try making a more minimal repro
rubenf
rubenf3w ago
nvm the null arg is for hash
httpteapot
httpteapot3w ago
Still an error with :
import * as wmill from "windmill-client"

export async function main() {
return await wmill.runScript('/u/maxime/demo_with_jsdom', null, {a: 3})
}
import * as wmill from "windmill-client"

export async function main() {
return await wmill.runScript('/u/maxime/demo_with_jsdom', null, {a: 3})
}
// maxime/demo_with_jsdom
import { JSDOM } from "jsdom";

export async function main(a: number) {
const test = new JSDOM();
return { a, test };
}
// maxime/demo_with_jsdom
import { JSDOM } from "jsdom";

export async function main(a: number) {
const test = new JSDOM();
return { a, test };
}
Isn't it the recommanded way to call a script "manually" in code without creating a flow? (It works if I remove jsdom)
rubenf
rubenf3w ago
it doesn't make a difference calling it in code or with api or in a flow as far as the script execution is concerned run it with //nobundling at the top probably jsom doesn't support well to be bundled
httpteapot
httpteapot3w ago
Yes it works with nobundling I tried to track down the issue locally running bun build on a script using jsdom, but I can't reproduce the issue. How are scripts bundled in windmill? It's not using bun build?
rubenf
rubenf3w ago
it's using bun build
httpteapot
httpteapot3w ago
When I bun build the following file, and then execute it, it works
import { JSDOM } from "jsdom";

export async function main(a: number) {
const test = new JSDOM();
return { a, test };
}

console.log(await main(1));
import { JSDOM } from "jsdom";

export async function main(a: number) {
const test = new JSDOM();
return { a, test };
}

console.log(await main(1));
rubenf
rubenf3w ago
GitHub
windmill/backend/windmill-worker/loader_builder.bun.js at a24365237...
Open-source developer platform to power your entire infra and turn scripts into webhooks, workflows and UIs. Fastest workflow engine (13x vs Airflow). Open-source alternative to Retool and Temporal...
rubenf
rubenf3w ago
actually that's not what is ran @httpteapot I investigated and you can reproduce the issue locally by removing node_modules after creating the bundle. The bundle still has references to files in the node_modules
httpteapot
httpteapot3w ago
Ok, so this is a bug with bun?
rubenf
rubenf3w ago
yes
httpteapot
httpteapot3w ago
GitHub
Reference to external module when bundling jsdom · Issue #14011 · o...
What version of Bun is running? 1.1.27+267afa293 What platform is your computer? Darwin 24.0.0 arm64 arm What steps can reproduce the bug? Bundling a script depending on jsdom is broken. To reprodu...
rubenf
rubenf3w ago
👍