kkinnear / zprint

Executables, uberjar, and library to beautifully format Clojure and Clojurescript source code and s-expressions.
MIT License
555 stars 47 forks source link

Build errors using zprint in figwheel project #246

Closed esciafardini closed 2 years ago

esciafardini commented 2 years ago

Adding zprint to a figwheel project & getting the following error message upon build:

08:24:07 cljs | WARNING: Use of undeclared Var cljs.tools.reader.reader-types/reader-error at line 9 resources/public/js/app.out/rewrite_clj/reader.cljs
08:24:07 cljs | WARNING: var: cljs.tools.reader/read-token is not public at line 182 resources/public/js/app.out/rewrite_clj/reader.cljs
08:24:07 cljs | WARNING: Wrong number of args (2) passed to cljs.tools.reader/read-token at line 182 resources/public/js/app.out/rewrite_clj/reader.cljs
08:24:09 cljs | WARNING: var: rewrite-clj.reader/whitespace? is not public at line 149 resources/public/js/app.out/rewrite_clj/parser/core.cljs
08:24:11 cljs | Failed to compile build :dev from ["d/src/" "sh-src"] in 50.627 seconds.
08:24:11 cljs | ----  Could not Analyze  resources/public/js/app.out/zprint/comment.cljc  ----
08:24:11 cljs |
08:24:11 cljs |   Invalid :refer, var rewrite-clj.zip/left* does not exist
08:24:11 cljs |
08:24:11 cljs | ----  Analysis Error : Please see resources/public/js/app.out/zprint/comment.cljc  ----

It appears to be having issues finding left* which is not present in the newer version of rewrite-clj. I've checked my dependencies via lein tree :deps and nothing is bringing in another version of rewrite-clj, so I'm not sure what's happening...

Attempted solutions (in project.clj file):

[rewrite-clj/rewrite-clj "1.0.767-alpha"]
[zprint "1.2.3" :exlusions [rewrite-clj/rewrite-clj]]

This did not work...

For some reason this makes everything work (in project.clj file):

[cljfmt "0.8.2" :exclusions [rewrite-clj]]
[zprint "1.2.3"]

It was an accidental solution as I was experimenting with both zprint & cljfmt for a feature I'm working on. I want to use zprint - but when I removed the dependency for cljfmt, I started getting the error message.

Any insights would be greatly appreciated!!!

esciafardini commented 2 years ago

The only difference in deps when diff'ing the results of lein deps :tree I see is the following:

kkinnear commented 2 years ago

I'm pressed for time just now, but you might look at Issue #231 where someone had problems with Figwheel, and I managed to replicate the problem and find a workaround for them. It too had to do with rewrite-clj/rewrite-cljs.

When I have a chance (soon, I hope), I'll see what I can figure out about your specific situation.

esciafardini commented 2 years ago

Hey, thanks for the response. I did see that issue - that's where I got the idea to play with dependencies, nothing I have has rewrite-clj as a dependency.

It's strange, when I bring in clj-fmt as a dependency (which does require rewrite-clj) the build succeeds.

No rush, thank you

kkinnear commented 2 years ago

In order to try to reproduce this issue, it would help a lot to have your project.clj. I need to reproduce your dependencies in order to be able to get it to fail the way it does for you. Thanks!

esciafardini commented 2 years ago

Ah, okay, makes sense. I'm going to try digging a little more with lein with-profile dev deps :tree - since the issue only happens in development mode....

Will update you asap.

kkinnear commented 2 years ago

Did you try the exclusion I added in Issue #231? I'm pretty sure that (at least the version I worked with then) Figwheel has rebelreadline in it, and that has rewrite-clj(s) in it, which causes the problem. If you add the exclusion from #231 to your project.clj, you might be in luck.

esciafardini commented 2 years ago
   :dev {:jvm-opts  [...]
         :source-paths ["src"]
         :dependencies 
                        [[org.clojars.runa/conjure "2.1.3"]
                        [figwheel-sidecar "0.5.20" :exclusions [org.clojure/tools.nrepl]]
                        [metosin/reitit-dev "0.5.15"]
                        [ring/ring-mock "0.4.0"]
                        #_[cljfmt "0.8.2" :exclusions [rewrite-clj]] ;;makes zprint work with figwheel (why?)
                        [cider/piggieback "0.4.2"]
                        [criterium "0.4.6"]
                        [hiccup-find "1.0.1"]]
         :plugins 
                       [[com.jakemccrary/lein-test-refresh "0.23.0"]
                       [lein-cooper "1.2.2"]
                       [lein-figwheel "0.5.20"]
                       [lein-pdo "0.1.1"]]}

Isolated the issue to be in my :dev profile.... I don't have rebel-readline in my :dev dependencies (where figwheel is used), but I've narrowed it down to being an issue solely within figwheel....

esciafardini commented 2 years ago

Thanks for pointing me toward rebel-readline as the issue!

  :figwheel {:css-dirs ["resources/public/css"]
             :nrepl-port 7888
             :readline false
             ;; Load CIDER, refactor-nrepl and piggieback middleware
             :nrepl-middleware ["cider.piggieback/wrap-cljs-repl"
                                "cider.nrepl/cider-middleware"]}

This fixed the issue for me! We are using [lein-figwheel "0.5.20"].

Thanks again!!

esciafardini commented 2 years ago

Setting :readline to false was the fix,

kovasap commented 1 year ago

I'm having the same issue with the following deps.edn and haven't been able to pin down the cause yet. Will post here if I do.

{:paths ["src/main" "src/test" "resources"]
 :deps {clj-http/clj-http {:mvn/version "3.12.3"}
        cljs-ajax/cljs-ajax {:mvn/version "0.8.4"}
        com.taoensso/timbre {:mvn/version "5.2.1"}
        day8.re-frame/http-fx {:mvn/version "0.2.4"}
        http-kit/http-kit {:mvn/version "2.5.3"}
        metosin/reitit {:mvn/version "0.5.18"}
        metosin/ring-http-response {:mvn/version "0.9.3"}
        mount/mount {:mvn/version "0.1.16"}
        org.clojure/clojure {:mvn/version "1.11.1"}
        org.clojure/clojurescript {:mvn/version "1.11.54"}
        org.clojure/data.json {:mvn/version "2.4.0"}
        org.clojure/data.csv {:mvn/version "1.0.1"}
        org.clojure/tools.logging {:mvn/version "1.2.4"}
        re-frame/re-frame {:mvn/version "1.2.0"}
        reagent/reagent {:mvn/version "1.1.1"}
        zprint/zprint {:mvn/version "1.2.4"}
        ring-cors/ring-cors {:mvn/version "0.1.13"}
        ring-middleware-format/ring-middleware-format {:mvn/version "0.7.5"}
        ring/ring {:mvn/version "1.9.5"}
        ring/ring-defaults {:mvn/version "0.3.3"}
        ; See https://github.com/weavejester/hashp/pull/1
        com.gfredericks/user.clj {:mvn/version "0.1.0"}
        io.github.kovasap/perlin2d {:git/sha "bd6e8d60b83bdc2a8730dbd328c2899a90604773"}
        thheller/shadow-cljs {:mvn/version "2.19.2"}}

 :mvn/repos {"central" {:url "https://repo1.maven.org/maven2/"}
             "clojars" {:url "https://repo.clojars.org/"}}

 :aliases {:test {:extra-paths ["src/test"]
                  :extra-deps {lambdaisland/kaocha {:mvn/version "1.66.1034"}
                               lambdaisland/kaocha-cloverage {:mvn/version "1.0.75"}
                               day8.re-frame/test {:mvn/version "0.1.5"}}
                  :main-opts ["-m" "kaocha.runner"]}

           :clj-kondo
           {:extra-deps {clj-kondo/clj-kondo {:mvn/version "RELEASE"}}
            :jvm-opts ["-Dghostwheel.enabled=true"]
            :main-opts ["-m" "clj-kondo.main"]}

           :frontend
           {:main-opts ["-m" "shadow.cljs.devtools.cli"
                        "watch" ":app"]
            :extra-deps {binaryage/devtools {:mvn/version "1.0.6"}}}

           :repl/conjure
           {:extra-deps {nrepl/nrepl       {:mvn/version "0.9.0"}
                         cider/cider-nrepl {:mvn/version "0.28.4"}}
            :main-opts  ["-m" "nrepl.cmdline"
                         "--middleware" "[cider.nrepl/cider-middleware]"
                         "--interactive"]}
           :api {:main-opts ["-m" "app.api"]}}}
kovasap commented 1 year ago

Updating to cljfmt 0.9.2 in my global ~/.clojure directory solved my problem: https://github.com/kovasap/dotfiles/commit/e4475e4224f747b7cab4507f8dcdd61f8e1f3015

rlovtangen commented 10 months ago

Updating to cljfmt 0.9.2 in my global ~/.clojure directory solved my problem: kovasap/dotfiles@e4475e4

Updating cljfmt worked for me as well, and the reason was this:

rebel-readline 0.1.4 brings in cljfmt 0.5.7 which brings inn both rewrite-clj 0.5.2 and rewrite-cljs 0.4.3.

rewrite-clj 1.x is a merge of rewrite-clj 0.x and rewrite-cljs 0.x, which means you should not have rewrite-cljs on classpath if you already have rewrite-clj 1.x. I had rewrite-clj 1.1.47 on classpath because of zprint 1.2.7 (because of re-frame-10x 1.9.3)

Upgrading cljfmt to 0.9.2 worked because it brings in rewrite-clj 1.1.45 instead of both rewrite-clj 0.x and rewrite-cljs 0.x. So rather than upgrading cljfmt I could also fix the problem by excluding rewrite-cljs from rebel-readline:

com.bhauman/rebel-readline {:mvn/version "0.1.4" :exclusions [rewrite-cljs/rewrite-cljs]}

With that said, maybe updating cljfmt is a better solution.