Fork me on GitHub
#shadow-cljs
<
2020-02-21
>
cfleming08:02:33

@thheller Congrats on a great performance by shadow in the state of Clojure survey, more REPL users than figwheel main now!

👍 1
thheller10:02:00

numbers are skewed because of the 2 figwheel variants though 😉

thheller10:02:36

> wtf does shadow-cljs do?

p-himik15:02:19

To be honest, that was my reaction as well when I first heard an advice about trying shadow-cljs out. "Wha... what? Why? Another build tool? No, I'm exhausted by their proliferation, thank you."

thheller10:02:39

some of the comments 😛

sheluchin12:02:11

I'm trying to get a new Fulcro3 project started using lein instead of deps.edn as the Fulcro tutorial suggests. When trying to run npx shadow-cljs start, I get this in my error log:

Exception in thread "main" Syntax error compiling . at (shadow/build/closure.clj:69:5).
Followed by a massive stacktrace that - at least to me - doesn't contain anything useful in determining what the error is. How might I go about figuring out what the issue is? I'm not terribly familiar with build tools and it might very well be a simple error in my config files, but I don't know how to determine that.

thheller12:02:49

strange error. only thing I can think of is likely dependency conflicts

sheluchin12:02:25

Hmm, I could pair those down to bare essentials. I copied them over from a previous project, but went to latest shadow-cljs.

thheller12:02:41

what do you have in project.clj dependency wise?

sheluchin12:02:26

(defproject prj "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url ""
  :license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
            :url ""}
  :dependencies [[org.clojure/clojure "1.10.0"]
                 [com.fulcrologic/fulcro "3.0.1"]]
  :main ^:skip-aot sheluchin.client
  :target-path "target/%s"
  :profiles {:uberjar {:aot :all}
             :dev {:source-paths ["src/prj/"]
                   :dependencies [[org.clojure/clojurescript  "1.10.520"]
                                  [thheller/shadow-cljs       "2.8.83"]
                                  [binaryage/devtools         "0.9.10"]]}})
                                  ; [cider/piggieback           "0.4.1"]]}})
                                  ; [fulcrologic/fulcro-spec    "3.1.4"]
                                  ; [com.fulcrologic/guardrails "0.0.9"]]}})

thheller12:02:25

try

[org.clojure/clojurescript "1.10.597"
    :exclusions [com.google.javascript/closure-compiler-unshaded
                 org.clojure/google-closure-library
                 org.clojure/google-closure-library-third-party]]

sheluchin12:02:15

Hmm, yeah, that worked. That's definitely not something I would have figured out lol

sheluchin12:02:32

What's the reason?

thheller12:02:12

the cljs version you had brought in an old closure-compiler version

sheluchin12:02:10

Should I keep the exclusions then?

thheller12:02:27

probably yeah

sheluchin12:02:15

How did you figure that out? Is it a reported issue or something?

g7s13:02:58

Can I have a :after-load/:before-load per module?

thheller15:02:30

@g7s use the metadata then you can have as many as you want

thheller15:02:43

they'll only trigger if the namespace is actually loaded

g7s15:02:39

I actually tried that and worked!

g7s15:02:12

really glad when things work as expected

Juleffel16:02:25

Hi all ! I'm new to shadowjs and trying to include [cljs-web3 "0.19.0-0-11"] to a re-frame project using shadow-cljs but I keep having this error while building:

The required JS dependency "web3" is not available, it was required by "cljsjs/web3.cljs".

Search in:
        /Users/jfleury/Documents/Git/multis-interview/node_modules
You probably need to run:
  npm install web3
I'm stuck on this, as when I run "npm install web3", it works, but package.json keeps being rewritten by the command lein-shadow - running shadow-cljs... somehow... I don't understand how to add a js package to project.clj... Can anyone help me on that ?

thheller16:02:16

can't really help you with the lein-shadow parts since I don't recommend using it

Juleffel16:02:27

Damn, I jsut copied the todomvc, it's used there 😕

thheller16:02:51

as for the web3 stuff you just install that that and require it directly (no cljsjs). (:require ["web3" :as web3]) or whatever the actual package name is

Juleffel16:02:52

Thanks, but the problem seems to be that I can't really install a npm package without adding something somewhere in project.clj or somewhere else, as the whole package.json is reset each time I launch my code... My project.clj is set like that:

(defproject xxx "lein-git-inject/version"

  :dependencies [[org.clojure/clojure        "1.10.1"]
                 [org.clojure/clojurescript  "1.10.597"
                  :exclusions [com.google.javascript/closure-compiler-unshaded
                               org.clojure/google-closure-library
                               org.clojure/google-closure-library-third-party]]
                 [thheller/shadow-cljs       "2.8.83"]
                 [reagent                    "0.9.1"]
                 [binaryage/devtools         "0.9.10"]
                 [clj-commons/secretary      "1.2.4"]
                 [re-frame                   "0.11.0"]
                 [day8.re-frame/tracing      "0.5.3"]
                 [day8.re-frame/test         "0.1.5"]
                 [day8.re-frame/re-frame-10x "0.5.2"]
                 [cljs-web3                  "0.19.0-0-11"]
                 [district0x.re-frame/web3-fx "1.0.5"]]

  :plugins      [[day8/lein-git-inject "0.0.11"]
                 [lein-shadow          "0.1.7"]
                 [lein-shell           "0.5.0"]]

  :middleware   [leiningen.git-inject/middleware]

  :clean-targets ^{:protect false} [:target-path
                                    "shadow-cljs.edn"
                                    ;"package.json"
                                    ;"package-lock.json"
                                    "resources/public/js"]

  :shadow-cljs {:nrepl {:port 8777}

                :builds {:client {:target :browser
                                  :output-dir "resources/public/js"
                                  :modules {:client {:init-fn xxx.core/main
                                                     :preloads [day8.re-frame-10x.preload]}}
                                  :compiler-options {:closure-defines {re-frame.trace.trace-enabled?        true
                                                                       day8.re-frame-10x.debug?             true
                                                                       day8.re-frame.tracing.trace-enabled? true}}
                                  :devtools {:http-root "resources/public"
                                             :http-port 8280}}
                         :karma-test {:target    :karma
                                      :ns-regexp "-test$"
                                      :output-to "target/karma-test.js"
                                      :compiler-options {:pretty-print    true
                                                         :closure-defines {re-frame.trace.trace-enabled? true}}}}}

  :aliases {"dev-auto" ["shadow" "watch" "client"]
            "test-once"  ["do"
                          ["clean"]
                          ["shadow" "compile" "karma-test"]
                          ["shell" "karma" "start" "--single-run" "--reporters" "junit,dots"]]
            "test-auto"  ["do"
                          ["clean"]
                          ["shadow" "watch" "karma-test"]]
            "karma-watch" ["shell" "karma" "start" "--reporters" "junit,dots"]})

thheller16:02:51

no clue. I recommend using shadow-cljs.edn and package.json for CLJS and not using lein-shadow

Juleffel16:02:32

thx, I will dig on that

thheller16:02:36

then you don't have those worries. I have never used lein-shadow and I'm not involved with it so can't help

thheller16:02:02

you probably already have the generated shadow-cljs.edn

Juleffel16:02:04

yes I have that

thheller16:02:17

then you just npm install shadow-cljs in the project

thheller16:02:23

and npx shadow-cljs watch client

thheller16:02:55

and remove shadow-cljs.edn from the :clean-targets. otherwise lein will delete it

thheller16:02:21

and you can then remove the :shadow-cljs stuff as well. basically what the plugin does is copy that to shadow-cljs.edn

ShaneLester16:02:12

Is there an easy way to configure shadow such that I can run a lein plugin before compile? Essentially, it would be cool if I could call lein cljfmt on my code right before watch recompiles everything on saving a cljs file. This is dumb, doing this at a higher level :)

paul a22:02:51

i'm configuring my shadow-cljs builds incorrectly somehow, but i can't tell how. in my shadow-cljs.edn, the builds section looks like this:

{:source-paths
 ["src/cljc/"
  "src/cljs/"
  "test/cljs/"]

 :dependencies
 [[reagent "0.9.0-rc1"]
  [cider/cider-nrepl "0.22.0-beta8"]]

 :nrepl
 {:port 8202}

 :builds {:dev {:target :browser
                :modules {:main
                          {:entries [my-app.frontend]
                           :depends-on #{:cljs-base}}

                          :tracker
                          {:entries [my-app.tracker]
                           :depends-on #{:cljs-base}}

                          :cljs-base
                          {:entries []}}
                :output-dir "resources/public/assets/js"
                :asset-path "/assets/js"}

          :test {:target :browser-test
                 :test-dir "test/resources/public"
                 :devtools {:http-port 8021
                            :http-root "test/resources/public"}}}}

paul a22:02:04

it seems like the :test build configuration is clobbering the :dev build entirely; with my shadow-cljs.edn like that, if i do a dev build, i get a test build

paul a22:02:08

i'm running shadow-cljs via emacs+cider, if that matters.

lilactown22:02:16

is that your whole shadow-cljs.edn?

paul a22:02:16

no - the rest is not very exciting, but i'll edit that message for completeness' sake

lilactown22:02:33

how are you serving the :dev files?

paul a22:02:21

i don't know enough to answer that question

paul a22:02:58

i believe that emacs is running the equivalent of shadow-cljs watch dev, which i guess runs a process that serves the files?

lilactown22:02:34

> if i do a dev build, i get a test build how do you know you get a test build instead of a dev build?

lilactown22:02:41

do you go to a URL in your browser?

1
paul a22:02:31

oh no, i'm mistaken. i believe shadow-cljs is just writing the compilation results to a place where my webserver can find them

paul a22:02:27

various reasons; my test builds take much longer than my dev builds; emacs launches a UI when it runs shadowc-ljs, and it takes me to the test page when i run the test builds

lilactown22:02:31

I’m confused by what you’re saying here.

lilactown22:02:19

emacs asks to launch a browser window when you start a shadow-cljs build, yes. does it perchance open your browser to localhost:8021?

lilactown22:02:37

you don’t have an http-server configured for your :dev build, which is why I ask

lilactown22:02:47

so Emacs might just be guessing what to open

paul a22:02:57

er, yeah, it does take me to localhost:8021.

lilactown22:02:09

it’s unclear to me how you expect to actually interact with your web application

paul a22:02:12

if i omit the :test build configuration entirely, emacs will take me to localhost:9630

paul a22:02:29

i run a web server separately

lilactown22:02:35

9630 is the sort of default shadow-cljs UI

lilactown22:02:57

my guess is emacs is just assuming which one to open based on your shadow-cljs.edn

lilactown22:02:16

I’m struggling to see evidence that the :dev build is not running. when you open the page on your separate web server, do you not see your application running and changes not hot loading?

lilactown22:02:09

do you see messages in your REPL buffer saying :dev or :test are building?

paul a22:02:04

last night i was seeing test builds. i restarted every thing and now things are fine... sorry for the goose chase, this seems to be user-error on my part 😕

lilactown22:02:34

if it opened to localhost:8021, it’s going to show your last test build even if the watch isn’t running

lilactown22:02:12

glad it’s working now for you, at least

paul a22:02:18

that makes sense

paul a22:02:21

my test builds take several minutes and i could swear that i was seeing those even when i had requested dev builds. that was another source of confusion, but maybe the primary confusion was the localhost:8021 vs localhost:9630 business.

paul a22:02:44

but yeah, everything looks good now. thanks!