Hello…. It’s been ages since I tried to use nbb and I am running into a problem that goes well beyond my understanding on JavaScript / NodeJS,,,
I am trying to use figlet to generate some ASCII Art in my CLI app, and I am getting wild long stack traces that mean nothing to me.
I have figured out that figlet returns a promise, so I have wrapped my call in a p/let (promesa) so that it will be realised before I try to add it to the output, but I really can’t seem to figure out what I am doing wrong… 😞
❯ nbb
Welcome to nbb v1.3.196!
user=> (require '["figlet$default" :as fig])
nil
user=> (fig "hello world" (fn [err data] (.log js/console data)))
#object[Promise [object Promise]]
user=> _ _ _ _ _
| |__ ___| | | ___ __ _____ _ __| | __| |
| '_ \ / _ \ | |/ _ \ \ \ /\ / / _ \| '__| |/ _` |
| | | | __/ | | (_) | \ V V / (_) | | | | (_| |
|_| |_|\___|_|_|\___/ \_/\_/ \___/|_| |_|\__,_|Thx! I think that I can take it from there±
❯ nbb
Welcome to nbb v1.3.196!
user=> (require '["figlet$default" :as fig])
nil
user=> (require '[promesa.core :as p])
nil
user=> (type (fig "hello world"))
#object[Promise]
user=> (p/let [ascii (fig "hello world")] (println ascii))
_ _ _ _ _
| |__ ___| | | ___ __ _____ _ __| | __| |
| '_ \ / _ \ | |/ _ \ \ \ /\ / / _ \| '__| |/ _` |
| | | | __/ | | (_) | \ V V / (_) | | | | (_| |
|_| |_|\___|_|_|\___/ \_/\_/ \___/|_| |_|\__,_|
#<Promise[resolved:6]>
user=>Much appreciated - I had forgotten $default
i originally did the same as you
user=> (require '["figlet" :as fig])
user=> (fig "hello world" (fn [err data] (.log js/console data)))
"#error {:message \"c.call is not a function\", :data {:type :sci/error, :line 1, :column 1, :message \"c.call is not a function\", :sci.impl/callstack #object[cljs.core.Volatile {:val ({:line 1, :column 1, :ns #object[ot user], :file nil, :sci.impl/f-meta nil} {:line 1, :column 1, :ns #object[ot user], :file nil, :sci.impl/f-meta nil})}], :file nil}, :cause #object[TypeError TypeError: c.call is not a function]}"and then tried this
user=> (.keys js/Object fig)
#js ["default"]which is why i went to look up how to do it. spoiler alert, i searched in this channel for “default”. And then i see the readme for nbb has a section
Thanks 🙏 Knowing how / where to look is what I don’t do well with. This is really helpful, thanks
Yeah. I was worried I was over explaining but showing that discovery seemed useful
Is there a “cheatsheet” for how to understand http://npmjs.org usage docs in terms of how to make them work in cljs / nbb?
I’m not sure if it’s exactly what you’re looking for, but these examples from the shadow-cljs docs are the cheatsheet I use to add libraries to the :require form: https://shadow-cljs.github.io/docs/UsersGuide.html#_using_npm_packages
Thanks 🙏