This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-04-26
Channels
- # announcements (1)
- # atom-editor (7)
- # babashka (9)
- # beginners (46)
- # cider (1)
- # circleci (2)
- # clj-on-windows (1)
- # cljdoc (5)
- # cljsrn (2)
- # clojure (25)
- # clojure-austin (8)
- # clojure-brasil (4)
- # clojure-europe (52)
- # clojure-nl (1)
- # clojure-norway (162)
- # clojure-uk (2)
- # cursive (3)
- # datalevin (134)
- # datomic (16)
- # defnpodcast (8)
- # graphql (9)
- # honeysql (5)
- # hoplon (26)
- # hyperfiddle (18)
- # introduce-yourself (1)
- # lsp (4)
- # malli (19)
- # nbb (16)
- # nrepl (1)
- # practicalli (3)
- # releases (3)
- # shadow-cljs (36)
- # tools-deps (7)
- # vim (2)
- # xtdb (9)
I posted https://stackoverflow.com/questions/76106830/how-can-i-use-clojurescripts-hiccups-library-in-nbb on stack overflow and was directed here. My basic question is: how do I consume cljs libs within nbb (and manage them as deps)? I'm returning to clojure after some years away and i don't remember anything about the tooling--and nbb seems different than I remember anyway. Can someone point me to an example script that shows how to do this? I'm in a Linux environment.
Hi @U054XR6S6PQ!
Have you tried what I suggested in the SO answer?
Try to run bb --config nbb.edn -e nil
and see it what it does?
Nbb is a bit special in that it can't load all CLJS libs since the code has to be compatible with the ClojureScript interpreter that is used in nbb, but it seemed you didn't even reach that stage yet and had some other problem
No, I didn't understand that part of the reply yet. I just focused do far on generating the html from hiccups (which worked). Now I'm trying to understand the deps management side
I will try that and reply back here in a while (I'm away from my computer right now). Thanks so much for the reply.
Alright, I think we're in different timezones and it's getting late here but I'll surely check back tomorrow
I appreciate it!
So, here's my nbb.edn file:
{:deps
{hiccups/hiccups {:mvn/version "0.3.0"}}}
and here's the error when I run the command bb --config nbb.edn -e nil
:
Error: Could not find or load main class clojure.main
Caused by: java.lang.ClassNotFoundException: clojure.main
Exception in thread "main" java.io.FileNotFoundException: /home/sirrobert/.clojure/.cpcache/A4CEF68F951217FE6FE54759160B5276.cp (No such file or directory)
at [email protected]/java.io.FileInputStream.open0(FileInputStream.java)
at [email protected]/java.io.FileInputStream.open(FileInputStream.java:219)
at [email protected]/java.io.FileInputStream.<init>(FileInputStream.java:158)
at $fn__11617.invokeStatic(io.clj:229)
at $fn__11617.invoke(io.clj:229)
at $fn__11569$G__11523__11576.invoke(io.clj:69)
at $fn__11591.invokeStatic(io.clj:165)
at $fn__11591.invoke(io.clj:165)
at $fn__11530$G__11519__11537.invoke(io.clj:69)
at $reader.invokeStatic(io.clj:102)
at $reader.doInvoke(io.clj:86)
at clojure.lang.RestFn.invoke(RestFn.java:410)
at clojure.lang.AFn.applyToHelper(AFn.java:154)
at clojure.lang.RestFn.applyTo(RestFn.java:132)
at clojure.core$apply.invokeStatic(core.clj:669)
at clojure.core$slurp.invokeStatic(core.clj:7009)
at clojure.core$slurp.doInvoke(core.clj:7009)
at clojure.lang.RestFn.invoke(RestFn.java:410)
at borkdude.deps$_main.invokeStatic(deps.clj:816)
at borkdude.deps$_main.doInvoke(deps.clj:589)
at clojure.lang.RestFn.applyTo(RestFn.java:137)
at clojure.core$apply.invokeStatic(core.clj:667)
at babashka.impl.deps$add_deps$fn__26946$fn__26947.invoke(deps.clj:101)
at clojure.lang.AFn.applyToHelper(AFn.java:152)
at clojure.lang.AFn.applyTo(AFn.java:144)
at clojure.core$apply.invokeStatic(core.clj:667)
at clojure.core$with_bindings_STAR_.invokeStatic(core.clj:1990)
at clojure.core$with_bindings_STAR_.doInvoke(core.clj:1990)
at clojure.lang.RestFn.invoke(RestFn.java:425)
at babashka.impl.deps$add_deps$fn__26946.invoke(deps.clj:101)
at babashka.impl.deps$add_deps.invokeStatic(deps.clj:101)
at babashka.main$exec$fn__31700.invoke(main.clj:872)
at clojure.lang.AFn.applyToHelper(AFn.java:152)
at clojure.lang.AFn.applyTo(AFn.java:144)
at clojure.core$apply.invokeStatic(core.clj:667)
at clojure.core$with_bindings_STAR_.invokeStatic(core.clj:1990)
at clojure.core$with_bindings_STAR_.doInvoke(core.clj:1990)
at clojure.lang.RestFn.invoke(RestFn.java:425)
at babashka.main$exec.invokeStatic(main.clj:824)
at babashka.main$main.invokeStatic(main.clj:1165)
at babashka.main$main.doInvoke(main.clj:1124)
at clojure.lang.RestFn.applyTo(RestFn.java:137)
at clojure.core$apply.invokeStatic(core.clj:667)
at babashka.main$_main$f__31813__auto____31823.invoke(main.clj:1204)
at clojure.lang.AFn.run(AFn.java:22)
at [email protected]/java.lang.Thread.run(Thread.java:1589)
at org.graalvm.nativeimage.builder/com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:775)
at org.graalvm.nativeimage.builder/com.oracle.svm.core.posix.thread.PosixPlatformThreads.pthreadStartRoutine(PosixPlatformThreads.java:203)
Exception in thread "main" java.lang.NullPointerException
at clojure.lang.RT.intCast(RT.java:1221)
at babashka.main$_main.invokeStatic(main.clj:1204)
at babashka.main$_main.doInvoke(main.clj:1190)
at clojure.lang.RestFn.applyTo(RestFn.java:137)
at babashka.main.main(Unknown Source)
As an aside (not directly about the deps failure), but the built-in reagent hiccups has some bumps: it has some react requirements like needing a key
property for lists. I'm not building a react app, but static html.
I'd much rather just bring it in clean and render html directly without reagent.
Thanks again for your help!
@U054XR6S6PQ re deps failure: can you try:
rm -rf ~/.deps.clj
bb --config nbb.edn -e nil
As for react keys: use render-to-string
instead. I understand you want only hiccup, but this is currently the recommended way in nbb.
One of the problems with hiccups is that it doesn't work in a CLJS-only environment due to this:
https://github.com/teropa/hiccups/blob/master/src/clj/hiccups/core.clj
It contains references to clojure.lang.PersistentVector
1. Great! That seems to have cleared up the deps issue. I guess all my fiddling around had created a dirty environment. 2. This is the way I am requiring it within my cljs script. Is this the recommended method? I don't quite understand the implications of the two forms I've seen.
(ns example)
(require '[reagent.dom.server :refer [render-to-string]])
(require '[cljs.reader :refer [read-string]])
(defn render [content]
(render-to-string
(read-string content)))
#js {:render render}
Finally, that makes sense about hiccups-- not a problem. I'm not even attached to it as a lib, I just remembered it from before and it seems like a clean approach.
Using render-to-string
(as in the snippet above), with the following html (taken from the hiccups page):
[:div
[:ul (for [x (range 1 4)] [:li x])]
[:p "Hello, World!"]]
I still get the following warning:
Warning: Each child in a list should have a unique "key" prop.
Check the top-level render call using <ul>. See for more information.
at x
<div><ul>for<x>range<!-- -->1<!-- -->4</x><li>x</li></ul><p>Hello, World!</p></div>
If that's normal, I can live with it; if not, I'd love to get rid of it =)
Thanks again!@U054XR6S6PQ Aha.. didn't know about those keys when just generating a string, that's a bit annoying yes. I once wrote a little hiccup function in user space when babashka didn't yet have one: https://github.com/babashka/babashka/blob/8c1077af00c818ade9e646dfe1297bbe24b17f4d/examples/notes.clj#L21