shadow-cljs

https://github.com/thheller/shadow-cljs | https://github.com/sponsors/thheller | https://www.patreon.com/thheller
defclass 2020-12-07T07:41:25.385100Z

Hello, I’m very new in shadow-cljs. I encounter a problem recently that I’m getting a ton of errors like these after invoke watch command. The compilation still works, but that’s making the console unusable.

[:failed-to-compare "^7.8.7" "7.12.5" #error {
 :cause "Cannot invoke \"Object.getClass()\" because \"target\" is null"
 :via
 [{:type java.lang.NullPointerException
   :message "Cannot invoke \"Object.getClass()\" because \"target\" is null"
   :at [clojure.lang.Reflector invokeInstanceMethod "Reflector.java" 97]}]
 :trace
 [[clojure.lang.Reflector invokeInstanceMethod "Reflector.java" 97]
  [shadow.cljs.devtools.server.npm_deps$make_engine invokeStatic "npm_deps.clj" 39]
  [shadow.cljs.devtools.server.npm_deps$make_engine invoke "npm_deps.clj" 32]
  [shadow.cljs.devtools.server.npm_deps$fn__17481$fn__17482 invoke "npm_deps.clj" 46]
  [clojure.lang.Delay deref "Delay.java" 42]
  [clojure.core$deref invokeStatic "core.clj" 2320]
  [clojure.core$deref invoke "core.clj" 2306]
  [shadow.cljs.devtools.server.npm_deps$fn__17481$fn__17484 invoke "npm_deps.clj" 52]
  [shadow.build.targets.browser$check_npm_versions$fn__18133$fn__18134 invoke "browser.clj" 826]
  [clojure.core.protocols$iter_reduce invokeStatic "protocols.clj" 49]
  [clojure.core.protocols$fn__8138 invokeStatic "protocols.clj" 75]
  [clojure.core.protocols$fn__8138 invoke "protocols.clj" 75]
  [clojure.core.protocols$fn__8088$G__8083__8101 invoke "protocols.clj" 13]
  [clojure.core$reduce invokeStatic "core.clj" 6828]
  [clojure.core$reduce invoke "core.clj" 6810]
  [shadow.build.targets.browser$check_npm_versions$fn__18133 invoke "browser.clj" 818]
  [shadow.build.targets.browser$check_npm_versions invokeStatic "browser.clj" 817]
  [shadow.build.targets.browser$check_npm_versions invoke "browser.clj" 799]
  [shadow.build.targets.browser$process invokeStatic "browser.clj" 854]
  [shadow.build.targets.browser$process invoke "browser.clj" 838]
  [clojure.lang.Var invoke "Var.java" 384]
  [shadow.build$process_stage$fn__14212 invoke "build.clj" 148]
  [shadow.build$process_stage invokeStatic "build.clj" 145]
  [shadow.build$process_stage invoke "build.clj" 137]
  [shadow.build$compile invokeStatic "build.clj" 408]
  [shadow.build$compile invoke "build.clj" 397]
  [shadow.cljs.devtools.api$release_STAR_ invokeStatic "api.clj" 353]
  [shadow.cljs.devtools.api$release_STAR_ invoke "api.clj" 340]
  [shadow.cljs.devtools.cli$do_build_command invokeStatic "cli.clj" 29]
  [shadow.cljs.devtools.cli$do_build_command invoke "cli.clj" 26]
  [shadow.cljs.devtools.cli$do_build_commands invokeStatic "cli.clj" 51]
  [shadow.cljs.devtools.cli$do_build_commands invoke "cli.clj" 40]
  [shadow.cljs.devtools.cli$main$body_fn__17101__auto____17691 invoke "cli.clj" 168]
  [shadow.cljs.devtools.cli$main invokeStatic "cli.clj" 167]
  [shadow.cljs.devtools.cli$main doInvoke "cli.clj" 134]
  [clojure.lang.RestFn applyTo "RestFn.java" 137]
  [clojure.core$apply invokeStatic "core.clj" 669]
  [clojure.core$apply invoke "core.clj" 660]
  [shadow.cljs.devtools.cli$_main invokeStatic "cli.clj" 221]
  [shadow.cljs.devtools.cli$_main doInvoke "cli.clj" 219]
  [clojure.lang.RestFn applyTo "RestFn.java" 137]
  [clojure.lang.Var applyTo "Var.java" 705]
  [clojure.core$apply invokeStatic "core.clj" 665]
  [clojure.main$main_opt invokeStatic "main.clj" 514]
  [clojure.main$main_opt invoke "main.clj" 510]
  [clojure.main$main invokeStatic "main.clj" 664]
  [clojure.main$main doInvoke "main.clj" 616]
  [clojure.lang.RestFn applyTo "RestFn.java" 137]
  [clojure.lang.Var applyTo "Var.java" 705]
  [clojure.main main "main.java" 40]]}]
I google for hours and no result, I’m curious is there a way for me to debug the process of compilation. Thanks very much.

defclass 2020-12-07T08:01:00.388100Z

clojure -M:cljs watch app , I use this command. Thank you all the same, Your help may lead me to find a solution : )

defclass 2020-12-07T08:05:07.388300Z

I saw these messages about 1 or 2 days ago.

wontheone1 2020-12-07T08:05:50.388500Z

I just advise you to go through git diff what broke it

wontheone1 2020-12-07T08:06:41.388700Z

going through change by change, pin point what change broke it 🙂

defclass 2020-12-07T08:08:09.388900Z

Thanks for your advice. I reset the codebase, but did not work. I guess something broken out the codebase.

defclass 2020-12-07T09:00:42.389200Z

I found it was a problem with jdk. It works when I downgrade jdk from 15 to 1.8. Thanks for your help @wontheone1: )

wontheone1 2020-12-07T09:01:00.389400Z

Aha no problem

wontheone1 2020-12-07T09:01:11.389600Z

I think JDK 8 is the most stable version with Clojure 🙂

❤️ 1
wontheone1 2020-12-07T09:01:22.389800Z

Good that you found out!

defclass 2020-12-07T09:03:27.390Z

I recall that I executed brew upgrade unconsciously yesterday 😭

wontheone1 2020-12-07T09:04:53.390300Z

😄 brew fucked up my python environments few times as well

wontheone1 2020-12-07T07:42:37.385500Z

what does your shadow-cljs.edn look like?

defclass 2020-12-07T07:45:52.385800Z

@wontheone1 It may be a bit verbose. I use deps.edn with shadow-cljs. the deps.edn:

{:paths ["src/main"]
 :deps
 {org.clojure/clojure         {:mvn/version "1.10.1"}
  rum/rum                     {:mvn/version "0.12.3"}
  ;; rum                         {:local/root "/home/tienson/codes/source/clj/rum"}
  ;; persistent-sorted-set       {:mvn/version "0.1.2"}
  ;; FIXME: doesn't work on my archlinux laptop (tienson)
  ;; The required namespace "datascript.core" is not available, it was required by "frontend/db.cljs".
  datascript/datascript       {:git/url "<https://github.com/tiensonqin/datascript>",
                               :sha "7c2822565d9a114c7d8604c335af89de4640e2e5"}
  ;; datascript                  {:mvn/version "1.0.1"}
  datascript-transit/datascript-transit
                              {:mvn/version "0.3.0"
                               :exclusions [datascript]}
  funcool/promesa             {:mvn/version "4.0.2"}
  medley/medley               {:mvn/version "1.2.0"}
  metosin/reitit-frontend     {:mvn/version "0.3.10"}
  cljs-bean/cljs-bean         {:mvn/version "1.5.0"}
  prismatic/dommy             {:mvn/version "1.1.0"}
  org.clojure/core.match      {:mvn/version "1.0.0"}
  com.andrewmcveigh/cljs-time {:mvn/version "0.5.2"}
  cljs-drag-n-drop/cljs-drag-n-drop
                              {:mvn/version "0.1.0"}
  borkdude/sci                {:mvn/version "0.1.1-alpha.6"}
  hickory/hickory             {:mvn/version "0.7.1"}
  hiccups/hiccups             {:mvn/version "0.3.0"}
  tongue/tongue               {:mvn/version "0.2.9"}
  org.clojure/core.async      {:mvn/version "1.3.610"}
  thheller/shadow-cljs        {:mvn/version "2.8.81"}
  expound/expound             {:mvn/version "0.8.6"}
  lambdaisland/glogi          {:mvn/version "1.0.74"}}

 :aliases {:cljs {:extra-paths ["src/dev-cljs/"]
                  :extra-deps  {org.clojure/clojurescript   {:mvn/version "1.10.597"}
                                thheller/shadow-cljs        {:mvn/version "2.8.81"}
                                binaryage/devtools          {:mvn/version "0.9.10"}
                                org.clojure/tools.namespace {:mvn/version "0.2.11"}
                                cider/cider-nrepl           {:mvn/version "0.23.0-SNAPSHOT"}}
                  :main-opts ["-m" "shadow.cljs.devtools.cli"]}
           :test
           {:extra-paths ["src/test/"]
            :extra-deps  {org.clojure/clojurescript {:mvn/version "1.10.520"}
                          org.clojure/test.check {:mvn/version "RELEASE"}}
            :main-opts   ["-m" "shadow.cljs.devtools.cli"]}
           :runner
           {:extra-deps
            {com.cognitect/test-runner
             {:git/url "<https://github.com/cognitect-labs/test-runner>",
              :sha "76568540e7f40268ad2b646110f237a60295fa3c"}},
            :main-opts ["-m" "cognitect.test-runner" "-d" "test"]}}}
and the shadow-cljs.
{:deps     true
 :nrepl        {:port 8701}

 :builds
 {:app
  {:target :browser
   :module-loader true
   :modules {:main {:init-fn frontend.core/init}
             :code-editor
             {:entries [frontend.extensions.code]
              :depends-on #{:main}}}

   :output-dir "./static/js"
   :asset-path "/static/js"
   :release {:asset-path "<https://asset.logseq.com/static/js>"}
   :compiler-options {:infer-externs :auto
                      :output-feature-set :es6
                      :externs ["datascript/externs.js"
                                "externs.js"]}
   :closure-defines {goog.debug.LOGGING_ENABLED true
                     frontend.config/GITHUB_APP_NAME #shadow/env "GITHUB_APP2_NAME"}

   :devtools
   ;; before live-reloading any code call this function
   {:before-load frontend.core/stop
    ;; after live-reloading finishes call this function
    :after-load frontend.core/start
    :preloads     [devtools.preload]}}

  :test
  {:target :node-test
   :output-to "static/tests.js"}

  :publishing
  {:target :browser
   :module-loader true
   :modules {:main {:init-fn frontend.publishing/init}
             :code-editor
             {:entries [frontend.extensions.code]
              :depends-on #{:main}}}

   :output-dir "./static/js/publishing"
   :asset-path "/static/js"

   :closure-defines {frontend.config/PUBLISHING true
                     goog.debug.LOGGING_ENABLED true}

   :compiler-options {:infer-externs :auto
                      :output-feature-set :es6
                      :externs ["datascript/externs.js"
                                "externs.js"]}
   :devtools
   ;; before live-reloading any code call this function
   {:before-load frontend.core/stop
    ;; after live-reloading finishes call this function
    :after-load frontend.core/start
    :preloads     [devtools.preload]}}}}

wontheone1 2020-12-07T07:47:24.386100Z

do you have :target key in the edn?

defclass 2020-12-07T07:49:05.386500Z

Sorry, yes,I have a :target key . app target is :browser

wontheone1 2020-12-07T07:51:22.386700Z

hmm

wontheone1 2020-12-07T07:51:58.386900Z

did you run compile or watch to build dev version and opened a browser to provide runtime?

wontheone1 2020-12-07T07:52:28.387100Z

When do you get those error messages

defclass 2020-12-07T07:54:27.387300Z

yep, I guess it might be caused by some of my environment changed yesterday. The config works well for a long time.

wontheone1 2020-12-07T07:57:30.387500Z

sorry I have no idea

wontheone1 2020-12-07T07:57:54.387700Z

Also when do you see these msgs? what command did you run?

wontheone1 2020-12-07T07:58:12.387900Z

or did you run the build with node ?

thheller 2020-12-07T09:13:21.391100Z

@michael.wong upgrade shadow-cljs. then jdk15 is just fine. I use it myself.

thheller 2020-12-07T09:13:45.391400Z

this jdk8 recommendation needs to die.

thheller 2020-12-07T09:14:37.392Z

thheller/shadow-cljs {:mvn/version "2.8.81"} is ancient history by now

thheller 2020-12-07T09:15:03.392200Z

as is org.clojure/clojurescript {:mvn/version "1.10.520"}

defclass 2020-12-07T09:17:25.393600Z

OK, thanks for advice, We will update the version at some future time. At present I need to ensure that our legacy code runs normally.

mkvlr 2020-12-07T09:24:26.394400Z

do I remember correctly that ReferenceError: $jscomp is not defined in a release build points towards an issue with polyfills?

thheller 2020-12-07T09:28:18.394900Z

yes, $jscomp is polyfills. thought I fixed all the issues though?

mkvlr 2020-12-07T09:31:06.395400Z

still running it one, but only in production, not doing a local release

mkvlr 2020-12-07T09:31:35.395900Z

we’re on 2.11.5 in this project, let me try upgrading first

thheller 2020-12-07T09:32:56.396300Z

bumping to the appropriate :output-feature-set is always the best option

mkvlr 2020-12-07T09:51:08.396700Z

hmm, still occurring with :output-feature-set :es8

mkvlr 2020-12-07T10:21:53.397100Z

nevermind, caching is hard…