Fork me on GitHub
#shadow-cljs
<
2023-11-09
>
michaeldrogalis21:11:22

Hey friends. Thanks for making shadow-cljs! I'm really enjoying it! I'm stuck on one thing, though. I have my project working in development mode, which targets the browser. However, when I make a release build, I get an error "Uncaught Error: Invalid arity: 4" with an incomprehensible stacktrace. Can anyone help me where to start?

michaeldrogalis21:11:04

I suspect the problem happens because Im using the react-syntax-highlighter library.

["react-syntax-highlighter/dist/esm/prism-light.js$default" :as SyntaxHighlighter]
But I don't know what might be wrong or how to fix it

michaeldrogalis21:11:23

It seems if I set optimizations to :simple, it all works ok 🙂 Curious what might be going on though

hifumi12322:11:33

npm code should all go through simple optimizations already. do you have a small example of your code and build configuration

hifumi12322:11:16

my only guess at the moment is that npm code somehow went through advanced optimizations, which is only possible in shadow-cljs if you explicitly set that cf. https://shadow-cljs.github.io/docs/UsersGuide.html#js-provider

michaeldrogalis22:11:04

{:lein {:profile "+cljs"}

 :builds
 {:website
  {:target :browser
   :output-dir "public/js"
   :asset-path "/js"
   :modules {:shared {:entries []}

             :index {:init-fn io.shadowtraffic.website.index/init
                     :depends-on #{:shared}}

             :pricing {:init-fn io.shadowtraffic.website.pricing/init
                       :depends-on #{:shared}}

             :contact {:init-fn io.shadowtraffic.website.contact/init
                       :depends-on #{:shared}}}
   :preloads [devtools.preload]
   :dev {:compiler-options
         {:optimizations :simple
          :closure-defines
          {re-frame.trace.trace-enabled?        true
           day8.re-frame.tracing.trace-enabled? true}}}}}

 :dev-http {8080 "public"}}

michaeldrogalis22:11:13

(I explicitly set simple to fix what I was running into)

michaeldrogalis22:11:47

Anyway, I wont make you run it down since it all seems good enough at the moment. Thank you for taking a stab at a hypothesis 🙂

thheller07:11:58

you can use npx shadow-cljs release website --pseudo-names to make the stacktrace somewhat legible

thheller07:11:26

or npx shadow-cljs release website --debug to also add source maps, which makes everything somewhat debuggable, although sometimes source maps actually make it more complicated. definitely try though.

thheller07:11:29

Uncaught Error: Invalid arity: 4 is usually an IFn.invoke related error, i.e. calling a (thing 1 2 3 4) when thing is something implementing IFn but omitting that arity

thheller07:11:17

don't use :simple or --debug/--pseudo-names builds in production though, they are far too huge

thheller09:11:31

what is always a possibility and can be rather hard to track down is externs related things. if --pseudo-names fixes it, it most certainly is externs related. most often this is caused by "incorrect" JS interop or not accounting for external JS included in the page but having no externs present. one cause is for example google analytics with its ga variable. ga is very likely variable name to be generated by :advanced. so effectively google analytics (or any other JS, not part of the build) replaces your code in bad ways, leading to errors such as this

michaeldrogalis15:11:05

Aha, thanks for letting me know. Ill try to track this down today then

michaeldrogalis18:11:18

This weirdly seems to have resolved itself. At some point I had to rm my .shadow-cljs directory to fix another issue. Perhaps something got gunked up there

thheller19:11:06

that unfortunately doesn't mean it is fixed. :advanced is not fully deterministic, so it might have chosen a different variable name and avoided the conflict. or moved it somewhere else. definitely verify if you have any other external JS on the page that don't have externs