clojurescript

Shantanu Kumar 2025-05-27T11:45:24.318379Z

Hi, I'm running into errors with the cljs-ajax (0.8.4) library with Node.js (22.15) and CLJS (1.11.132 and 1.12.42): 1. First, I get this error (with stack trace):

node:internal/modules/cjs/loader:1404
  throw err;
  ^

Error: Cannot find module 'xmlhttprequest'
2. When I create an empty package.json and run npm i xmlhttprequest, I start getting this error (with stack trace):
ReferenceError: XMLHttpRequest is not defined
This ^ is without adding :api (js/XMLHttpRequest.) to the request map when calling ajax.core/ajax-request. Can anyone share a pointer on what am I missing?

p-himik 2025-05-27T11:55:41.141609Z

No clue what the issue is but FWIW personally I'd use the built-in fetch API, unless you really need to have the the same CLJ and CLJS code that makes requests.

Shantanu Kumar 2025-05-27T12:02:27.365189Z

@p-himik Thanks for the suggestion. I have some CLJC code that needs to use this, hence cljs-ajax. A fallback option could be to use hato and fetch with reader conditional.

Shantanu Kumar 2025-05-27T12:30:43.912869Z

Update: Got over the error with these additional steps: 3. Add this entry to :require in the ns block:

#?(:cljs ["xmlhttprequest" :as xhr])
4. Added this just below the ns block (before making any cljs-ajax call):
#?(:cljs (set! js/XMLHttpRequest xhr.XMLHttpRequest))

p-himik 2025-05-27T13:07:27.619329Z

Oof. Honestly, with such hackery I'd myself definitely start considering other options. Some examples, if you care (there are likely to be more, I just didn't look too deep): • https://github.com/oliyh/martianhttps://github.com/cjohansen/courier Maybe relevant to your case, can't really tell: https://github.com/JulianBirch/cljs-ajax/issues/214 If not, it might be worth it to create a new issue.

Shantanu Kumar 2025-05-27T13:12:34.574819Z

@p-himik Thanks for the resources! I am actually considering other options due to the hackery involved. 😄