shadow-cljs

pez 2025-05-10T07:12:48.491569Z

I have an issue where I can’t use Promesa in a :node-script target. It’s in an MCP server, and most clients work fine, except Claude Desktop which finds some code path where something crashes inside Promesa code. It’s a small script and I have removed Promesa from it so my project is fine. But I wonder what to do with reporting the problem. My repro isn’t exactly minimal, and I don’t understand at all why this happens. I don’t know if it’s a ClojureScript thing, Promesa, maybe even shadow. What would be my next step in trying to isolate and find more information about it? I get different crash logging when using ClojureScript 1.12.38 (nothing), than with 1.11.132 (a stack trace pointing me to Promesa).

thheller 2025-05-10T07:21:28.188059Z

well how does it fail? stack trace with async code can be tricky

thheller 2025-05-10T07:22:27.372149Z

I'd bet money its neither of those things and rather a problem in your code 😛

thheller 2025-05-10T07:22:57.305889Z

well actually I take that back. I never liked how promesa wraps promises and stuff

pez 2025-05-10T07:55:03.222749Z

The error message seems to be about syntax of the generated JS code.. Here’s the trace:

2025-05-10T07:42:07.193Z [backseat-driver] [info] Initializing server...
2025-05-10T07:42:07.219Z [backseat-driver] [info] Server started and connected successfully
2025-05-10T07:42:07.220Z [backseat-driver] [info] Message from client: {"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"claude-ai","version":"0.1.0"}},"jsonrpc":"2.0","id":0}
/Users/pez/Projects/calva-mcp-server/.shadow-cljs/builds/stdio-wrapper/dev/out/cljs-runtime/promesa.impl.promise.js:176
      this[QUEUE].push({type:RESOLVE_TYPE_FLATTEN, resolve:resolve ?? defaultResolveMapHandler, reject:reject ?? defaultRejectHandler, complete:completeDeferredFn(deferred)});
                                                                    ^

SyntaxError: Unexpected token ?
    at new Script (vm.js:80:7)
    at createScript (vm.js:274:10)
    at Object.runInThisContext (vm.js:326:10)
    at global.SHADOW_IMPORT (/Users/pez/Projects/calva-mcp-server/dist/calva-mcp-server.js:56:15)
    at /Users/pez/Projects/calva-mcp-server/dist/calva-mcp-server.js:1457:1
    at Object.<anonymous> (/Users/pez/Projects/calva-mcp-server/dist/calva-mcp-server.js:1464:3)
    at Module._compile (internal/modules/cjs/loader.js:701:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Module.load (internal/modules/cjs/loader.js:600:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
2025-05-10T07:42:07.956Z [backseat-driver] [info] Server transport closed
2025-05-10T07:42:07.956Z [backseat-driver] [info] Client transport closed
I think Claude Desktop is an Electron app. My script logs node version v10.15.3 . Which may not support the ?? syntax?

thheller 2025-05-10T07:58:07.671519Z

what ?? syntax? cljs doesn't generate that for anything?

🤭 1
thheller 2025-05-10T07:59:45.745509Z

ah promesa is just plain JS in that case. yeah no clue what that syntax even is 😛

thheller 2025-05-10T08:00:44.080009Z

I have literally never seen ?? before. don't even know what that does

thheller 2025-05-10T08:02:42.575319Z

could be that this is related to how :node-script loads code in development. does this also happen for release builds?

thheller 2025-05-10T08:02:51.730539Z

does electron still not support ESM code?

pez 2025-05-10T08:09:27.373609Z

Thanks. I knew I was asking in the right place. 😃

pez 2025-05-10T08:10:28.957079Z

Happens in release builds too.

thheller 2025-05-10T08:11:22.557439Z

then I'd get rid of promesa. I never like it trying to be clever and wrap promises

pez 2025-05-10T08:11:25.034559Z

OK, but then the right thing to do for this problem is to remove Promesa, since I can’t control what node environment the script is run from.

pez 2025-05-10T08:13:41.064969Z

I can still use Promesa in my server 😃 It runs in VS Code, where we have a more modern Electron. I think Electron may support ESM these days, but I don’t know if VS Code is using a modern enough Electron yet.

2025-05-11T06:40:19.213029Z

?? is the native nullish coalescence operator which is typically used like aVar ?? "default-value" where if aVar is null or undefined, "default-value" is selected. If the value is falsey like "", 0, or false, that value will be used. Roughly syntax sugar for:

(aVar === null || aVar === undefined) ? "default-value" : avar

thheller 2025-05-11T06:48:41.724019Z

what a sane language calls or 😉

🤘 2
pez 2025-05-11T07:10:27.541729Z

I think the syntax was inspired by optionality thinking.

2025-05-11T12:46:53.825219Z

It's different than or.

"" || "other" // => "other"
"" ?? "other" // => ""

thheller 2025-05-11T13:16:15.819059Z

I said sane language, so (or "" "other") 😉

😂 2
Marten Sytema 2025-05-10T09:52:41.725519Z

Hello Folks, I just got a new desktop Mac, and the vastly improved cores + memory made me wondering: what ways are there to tune my (CIDER) dev set up. I normally do cider-jack-in-clj&cljs which runs my clojure and shadow-cljs stuff in my mono repo for my web app. But would it speed things up (recompiles / hot reloads / startup times etc) if I for instance use different Xmx settings? What is the route. I asked chatGPT, but the result was a bit hallucinating afaict.

thheller 2025-05-10T10:26:44.536249Z

the jvm defaults are pretty good. I doubt there many gains to be had. only reason to ever use xmx is to reduce memory use if memory limits are hit

thheller 2025-05-10T10:27:15.284939Z

you could experiment with gc settings, but I also doubt that'll make any noticeable difference

👍 1
Marten Sytema 2025-05-10T10:36:38.302319Z

Alright thx