shadow-cljs

https://github.com/thheller/shadow-cljs | https://github.com/sponsors/thheller | https://www.patreon.com/thheller
2021-04-05T01:40:29.346400Z

I don't use them for anything special, other than visualizing in source tree which commit is which release. It's only useful for people looking at the source code.

2021-04-05T04:07:58.347600Z

Is the usage of ^:const (e.g. in (def ^:const my-var 3000)) still justified when using shadow-cljs?

thheller 2021-04-05T07:42:34.348900Z

^:const is probably the most misunderstood feature in CLJ(S) so I would avoid it. but you can use it if you must.

đź‘Ť 2
Stewart Foxall 2021-04-05T15:06:19.350300Z

Hi total newbie here. Just trying out shadow-cljs, but can’t seem to get past the intial step, am getting a binding error. [2021-04-05 15:44:22.985 - WARNING] :shadow.cljs.devtools.server/socket-repl-ex BindException Can’t assign requested address (Bind failed) http://java.net.PlainSocketImpl.socketBind (PlainSocketImpl.java:-2) http://java.net.AbstractPlainSocketImpl.bind (AbstractPlainSocketImpl.java:387) http://java.net.ServerSocket.bind (ServerSocket.java:375) http://java.net.ServerSocket.<init> (ServerSocket.java:237) shadow.cljs.devtools.server.socket-repl/start (socket_repl.clj:123) shadow.cljs.devtools.server.socket-repl/start (socket_repl.clj:115) shadow.cljs.devtools.server/start-system/fn--17877 (server.clj:233) shadow.cljs.devtools.server/start-system (server.clj:232) shadow.cljs.devtools.server/start-system (server.clj:202) shadow.cljs.devtools.server/start! (server.clj:483) shadow.cljs.devtools.server/start! (server.clj:385) shadow.cljs.devtools.server/start! (server.clj:388) BindException: Can’t assign requested address (Bind failed) http://java.net.PlainSocketImpl.socketBind (PlainSocketImpl.java:-2) http://java.net.AbstractPlainSocketImpl.bind (AbstractPlainSocketImpl.java:387) http://java.net.ServerSocket.bind (ServerSocket.java:375) http://java.net.ServerSocket.<init> (ServerSocket.java:237) shadow.cljs.devtools.server.socket-repl/start (socket_repl.clj:123) shadow.cljs.devtools.server.socket-repl/start (socket_repl.clj:115) shadow.cljs.devtools.server/start-system (server.clj:248) shadow.cljs.devtools.server/start-system (server.clj:202) shadow.cljs.devtools.server/start! (server.clj:483) shadow.cljs.devtools.server/start! (server.clj:385) shadow.cljs.devtools.server/start! (server.clj:388) shadow.cljs.devtools.server/start! (server.clj:385) shadow.cljs.devtools.server/from-cli (server.clj:615) shadow.cljs.devtools.server/from-cli (server.clj:591) clojure.lang.Var.applyTo (Var.java:705) clojure.core/apply (core.clj:665) clojure.core/apply (core.clj:660) shadow.cljs.devtools.cli-actual/lazy-invoke (cli_actual.clj:23) shadow.cljs.devtools.cli-actual/lazy-invoke (cli_actual.clj:20) shadow.cljs.devtools.cli-actual/blocking-action (cli_actual.clj:129) shadow.cljs.devtools.cli-actual/blocking-action (cli_actual.clj:116) shadow.cljs.devtools.cli-actual/main (cli_actual.clj:177) shadow.cljs.devtools.cli-actual/main (cli_actual.clj:132) clojure.core/apply (core.clj:669) clojure.core/apply (core.clj:660) shadow.cljs.devtools.cli-actual/-main (cli_actual.clj:219) shadow.cljs.devtools.cli-actual/-main (cli_actual.clj:217) clojure.lang.Var.applyTo (Var.java:705) clojure.core/apply (core.clj:665) clojure.core/apply (core.clj:660) shadow.cljs.devtools.cli/-main (cli.clj:75) shadow.cljs.devtools.cli/-main (cli.clj:67) clojure.lang.Var.applyTo (Var.java:705) clojure.core/apply (core.clj:665) clojure.main/main-opt (main.clj:514) clojure.main/main-opt (main.clj:510) clojure.main/main (main.clj:664) clojure.main/main (main.clj:616) clojure.lang.Var.applyTo (Var.java:705) clojure.main.main (main.java:40)

thheller 2021-04-05T15:07:01.350600Z

what binding error?

Stewart Foxall 2021-04-05T15:07:53.351100Z

Sorry first time using slack and it sent the message before I had finished typing

Stewart Foxall 2021-04-05T15:08:34.351700Z

I was using another example, but then switched to using this: https://github.com/shadow-cljs/quickstart-browser I am running on macos 11 if that is relevant

thheller 2021-04-05T15:09:52.352700Z

did you block it in your firewall? It needs to open a server socket so you can talk to it via the REPL etc

Stewart Foxall 2021-04-05T15:11:11.353300Z

Not as far as I am aware, I have nothing running, checked and can’t see that 8630 port is being used

thheller 2021-04-05T15:11:49.354Z

did you configure anything related to ports in shadow-cljs.edn? or is this with the default setup?

thheller 2021-04-05T15:12:45.355Z

only thing I can think of is your firewall blocking it

Stewart Foxall 2021-04-05T15:13:27.355900Z

I did on another example was learning on, but not for quick start. Just followed the commands as is. The file contents is:

;; shadow-cljs configuration
{:source-paths
 ["src/dev"
  "src/main"
  "src/test"]

 :dependencies
 []

 :dev-http
 {8020 "public"}

 :builds
 {:app
  {:target :browser
   :output-dir "public/js"
   :asset-path "/js"

   :modules
   {:main ; becomes public/js/main.js
    {:init-fn starter.browser/init}}}}}

thheller 2021-04-05T15:14:58.356200Z

that looks fine

Stewart Foxall 2021-04-05T15:15:18.356500Z

My firewall is off

thheller 2021-04-05T15:15:30.357Z

you can try adding :socket-repl false so it skips trying to start that

Stewart Foxall 2021-04-05T15:15:39.357400Z

sure

thheller 2021-04-05T15:15:44.357700Z

but likely it'll then just fail on the next network port it tries to use

Stewart Foxall 2021-04-05T15:15:51.357900Z

and thank you for helping

Stewart Foxall 2021-04-05T15:17:16.358800Z

To be clear, you mean like this:

;; shadow-cljs configuration
{:source-paths
 ["src/dev"
  "src/main"
  "src/test"]

 :dependencies
 []

 :socket-repl false

 :dev-http
 {8020 "public"}

 :builds
 {:app
  {:target :browser
   :output-dir "public/js"
   :asset-path "/js"

thheller 2021-04-05T15:17:21.359Z

yes

Stewart Foxall 2021-04-05T15:18:00.359500Z

Errors out again

thheller 2021-04-05T15:18:46.360400Z

it tries to bind to 0.0.0.0 by default which should be localhost. I do not know why it would fail. nobody else has reported this before.

thheller 2021-04-05T15:19:15.360900Z

or rather 127.0.0.1 for the socket-repl. maybe you only have ipv6 configured? no ipv4 at all?

thheller 2021-04-05T15:20:24.361400Z

or rather it tries to bind localhost. is that maybe not configured for some reason?

Stewart Foxall 2021-04-05T15:20:47.361600Z

Just taking a look now

thheller 2021-04-05T15:23:58.361900Z

try ping localhost in the terminal

Stewart Foxall 2021-04-05T15:25:33.362200Z

Looks like something to do with my ISP

thheller 2021-04-05T15:26:05.362700Z

that is odd. localhost shouldn't leave you machine at all.

thheller 2021-04-05T15:26:40.363100Z

I don't actually know where this is configured in macos anymore. maybe still /etc/hosts?

Stewart Foxall 2021-04-05T15:27:34.363300Z

Stewart Foxall 2021-04-05T15:27:51.363900Z

This may be the culprit

thheller 2021-04-05T15:30:05.364100Z

my macbook has

$ cat /etc/hosts
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost

Stewart Foxall 2021-04-05T15:30:36.364600Z

Yes just noticed 127.0.1 was not there, added in and refreshed working now. Thank you!!!!

thheller 2021-04-05T15:30:51.365Z

strange 🙂

Stewart Foxall 2021-04-05T15:31:17.365500Z

Very, must have been cleared some point in the past, thanks again…

Max 2021-04-05T16:23:27.366800Z

Is there a way to do dev-only dependencies with shadow-cljs, or do you have to integrate with deps or lein?

Azzurite 2021-04-05T16:39:39.367500Z

wouldn't dev-only dependencies be npm install &lt;package&gt; --save-dev?

Max 2021-04-05T16:51:48.367700Z

Not if it’s a maven/deps package

thheller 2021-04-05T17:08:47.368700Z

@max.r.rothman the distinction is not necessary. the builds decide what is included and as such having extra but unused dependencies on the classpath do not matter

thheller 2021-04-05T17:09:56.369400Z

just include everything all the time. shadow-cljs.edn itself does not have the concept of dev-dependencies.

Max 2021-04-05T17:10:52.370Z

Does that happen at all optimization levels? And how then do I configure a build to not include that code (or to only include that code in one build)?

thheller 2021-04-05T17:11:41.370700Z

you ns :require forms control what the build will actually use for all optimization levels

thheller 2021-04-05T17:12:15.371300Z

the build reports will tell you in detail what your build included https://shadow-cljs.github.io/docs/UsersGuide.html#build-report

Max 2021-04-05T17:12:19.371400Z

Nice! 🪄

Max 2021-04-05T17:13:55.372500Z

Sounds like there’s not a way to make certain namespaces or dependencies unavailable in certain builds though? I’d have to figure out some way of scraping the build report if I wanted to check that constraint automatically?

thheller 2021-04-05T17:16:08.373500Z

you could also verify with a build hook. in general you want to include dev-only code via :preloads. they are not included in the release builds

đź‘Ť 2
thheller 2021-04-05T17:16:29.373900Z

most cljs libs already provide instructions to do so, if that applies

cbc 2021-04-05T18:41:40.375700Z

hello, i'm new and i'm using shadow-cljs with cursive, and i can't get command completion to work for a js (actually typescript) library that i installed with npm...should there be a way to make this work?

thheller 2021-04-06T07:12:20.380500Z

pom.xml works fine, you do NOT need to use deps.edn or project.clj for Cursive. Regardless of what you use though Cursive does not support JS dependencies as of now

rkiouak 2021-04-07T16:22:52.453200Z

in my experience, there is definitely no need to manage dependencies in deps or project.clj, just want to echo thhellers comment (I find that managing npm deps in shadow-cljs.edn is FAR less maintenance work than dealing with deps.edn or project.clj finagling I end up doing when working with npm deps in those)

cbc 2021-04-05T18:45:35.375900Z

i created the project using the pom.xml as detailed here: https://shadow-cljs.github.io/docs/UsersGuide.html#_cursive

thheller 2021-04-05T20:23:56.376400Z

no, this is currently not support by Cursive

wilkerlucio 2021-04-05T20:38:58.378300Z

you must use a deps.edn or a project.clj to setup things for Clojure in Cursive

Azzurite 2021-04-05T20:52:41.378500Z

@wrokon with Cursive it's best to use deps.edn or leiningen project.clj for defining dependencies instead of shadow-cljs.edn

Jason 2021-04-05T21:46:01.379600Z

Does anyone have any experience building a project with Bazel? Apparently the best angle is to use the Closure rules but does that mean I should npm install shadow-cljs or clojurescript itself?

cbc 2021-04-05T22:10:35.379900Z

ok, thanks everyone, i will give it a try...for now i'm just living with all the unresolved symbols