Fork me on GitHub

I'm using a clojurescript repl through emacs + cider. Whenever I do a println from a not-immeditaly-resolved promise, the output gets lost (e.g. doesn't show up in the repl). The snippet below demonstrates this and is from the promesa docs. If I change the delay to 0, I see the expected output in the repl. If I run the cljs script from the cli, I also see the output. Any ideas? Or any pointers on where the culprit may be? There's a lot of elements in play here: emacs, cider, shadow-cljs, promesa, cljs compiler, etc, etc.


Does the output appear in the JS console?


If by JS console you mean in the brower, this is.a nodejs app. Is there typically a sperate JS console from what I see in the repl? js/console.log things end up in the repl.


No idea then, I have never tried running CLJS on NodeJS. js/console.log can easily be overwritten by the REPL machinery to specifically print into REPL. println calls cljs.core/*print-fn* to do the actual printing, which can also be overwritten by the REPL machinery - only this time not globally but on a per-call basis. Meaning, the default value of cljs.core/*print-fn* is something that doesn't print to the REPL.


Maybe something like this could shed some light:

(def orig-print-fn (atom nil))

(-> (p/delay 1000 "")
    (p/then (fn [_]
              (reset! orig-print-fn cljs.core/*print-fn*))))

;; Wait for one second


the shadow-cljs node-repl should capture all output


the node repl available for :node-script or :node-library builds does not, so there async output just goes to stdout not the REPL


dunno where emacs shows that


which REPL do you use?


@U05224H0W I'm 'jacking in' and then selecting shadow and node-repl. Does that answer your question?


@U2FRKM4TW when I run your suggestion, @orig-print-fn shows me the same symbol as cljs.core/*print-fn*


that is, #object[shadow$cljs$devtools$client$env$set_print_fns_BANG__$_repl_print_fn]


@U05224H0W my target is :node-script


> the node repl available for `:node-script` or `:node-library` builds does not, so there async output just goes to stdout not the REPL I think you're describing what I'm seeing? My async output is going somewhere where I can't see it, but my sync output is going to the repl.


then again, when I jack in, I don't select my specific target, :app, but select node-repl. 🤷


with node-repl you should see it but I don't have a clue regarding the emacs side


shadow-cljs node-repl you should be seeing the output


☝️ confirmed! it was helpful for me to at least narrow it down to a emacs/cider/nrepl issue. now I have a smaller area to investigate.


Interesting wrinkle: When I 'jack in' from emacs, I loose the async println's, but when I start the repl from the cli using npx shadow-cljs -d nrepl/nrepl:0.9.0-beta1 -d cider/piggieback:0.5.2 -d cider/cider-nrepl:0.26.0 node-repl and then use emacs to connect to the existing repl, I don't loose the async messages. (They show up in both the emacs repl and on the cli, the former being very convenient)


sorry don't have a clue regarding any emacs/cider stuff. node-repl should always give you all the output but all shadow-cljs can do is send nrepl messages for those. where or how cider displays them I don't know


I'm trying to add a UI component library (primereact) into a re-frame project but it can't find the dependency to import.. I've been added via yarn, do I also need to add it to, say, shadow-cljs.edn?


is it a npm library or cljs?


then just yarn should be enough


ok, I thought so.


Ok, so added it to yarn, tried to require it [primereact :as pr] and get The required namespace "primereact" is not available, it was required by "proj/views.cljs".


try "primereact"


as a string


Aha, one error closer: The required JS dependency "primereact" is not available, it was required by "pnx_web/views.cljs".


Ok, I think there's no top-level thing to import, it looks like you import per-component, so importing "primereact/button" :as pr-button worked, its just giving me guff here: Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: object.


but I think I'm at least past the import problem 🙂 thanks!


It still seems to be the import problem, but you have advanced a step more. Take a look at this section:


Thanks.. I've gotten decently familiar with (basic) clojure, and can write angular/react apps all day long, but definitely getting tripped up in the space between at the moment! 🙂


Hi there! I'm trying to learn clojurescript (and clojure!), and I'm having trouble getting things up and running. I compile my .cljs file using lein-cljsbuild, then I import the build code into an .html file using script tags. It seems like the main file cljsbuild generates is inert, though. It's just a bunch of calls to 'goog.addDependency'. I can import 'js/goog/base.js' first, and that allows the code to run without error, but nothing happens. I can then import my script, but I get errors because my dependencies aren't available. I'm pretty sure I need to do something to tell 'goog' to run my script for me, but I can't find any documentation on how to do that. I've read quite a few tutorials and documentation, but I can't find anything that addresses how to run clojurescript code once I've built it, which makes me feel like I'm going crazy.


goog.addDependency without any substance sounds like you're building a development build, not a release one. But maybe that's what you want. In either case, when you have the main entry point in your script, you have to call it somehow. There are multiple ways, and at least shadow-cljs has something specific to it. But on can override window.onload, you can export the function and call it explicitly in a separate <script> tag, or maybe even just call it at the end of the same script where it's defined (probably not great for hot-reloading your code).


Just in case it will look familiar to what lein-cljsbuild has, here's how it would look in shadow-cljs, notice that :init-fn key:


I was trying

(set! (.-onload js/window) (fn []
    (js/console.log "onready was called")
    (rdom/render [some-component] (js/document.querySelector ".app"))))
but a bunch of libraries I use weren't defined. It turns out, I was missing a compiler flag, :main "clojure-learning.client" , which tells cljsbuild to compile this as an exe and not a library, basically. I added that flag, and now the main.js file looks totally different and runs my code with the correct dependencies imported.


Also, I was ignoring 'shadow-cljs' because I assumed it was a shadow-dom thing, and I didn't care. Now that I see it's a clojurescript build tool, I'll definitely take a look at it.

👍 3

We've got a library written in clojurescript and I'd like to generate typescript annotations for people using it from typescript-land - has anyone done that before?


yes and no - I remember someone was trying to do something similar in #malli recently