nbb

maleghast 2025-03-14T20:27:17.934949Z

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… 😞

dpsutton 2025-03-14T20:34:00.901449Z

❯ 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 / (_) | |  | | (_| |
 |_| |_|\___|_|_|\___/    \_/\_/ \___/|_|  |_|\__,_|

maleghast 2025-03-14T20:36:52.860479Z

Thx! I think that I can take it from there±

👍 1
dpsutton 2025-03-14T20:37:04.972979Z

❯ 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=>

maleghast 2025-03-14T20:37:29.560919Z

Much appreciated - I had forgotten $default

dpsutton 2025-03-14T20:38:05.416219Z

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]}"

dpsutton 2025-03-14T20:38:15.259859Z

and then tried this

user=> (.keys js/Object fig)
#js ["default"]

dpsutton 2025-03-14T20:38:37.017249Z

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

maleghast 2025-03-15T17:56:08.258439Z

Thanks 🙏 Knowing how / where to look is what I don’t do well with. This is really helpful, thanks

dpsutton 2025-03-15T17:57:37.174009Z

Yeah. I was worried I was over explaining but showing that discovery seemed useful

maleghast 2025-03-14T20:27:52.281069Z

Is there a “cheatsheet” for how to understand http://npmjs.org usage docs in terms of how to make them work in cljs / nbb?

Byron Clark 2025-03-14T21:02:25.425799Z

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

maleghast 2025-03-15T17:51:53.671659Z

Thanks 🙏