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?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.
@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.
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))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/martian • https://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.
@p-himik Thanks for the resources! I am actually considering other options due to the hackery involved. 😄