Fork me on GitHub
#shadow-cljs
<
2020-03-05
>
defa14:03:39

I’m using https://github.com/juxt/tick in a :react-native target and the app will crash when running as a production build: shadow-cljs release app there is some information related to this library and shadow-cljs: https://github.com/henryw374/tick-on-shadow-cljs-demo that does not help with production builds. However, using shadow-cljs compile app before ./gradlew assembleRelease to skip optimisations will result in a working app. Any hints? I read the excellent documentation to shadow-cljs but seem to have missed something. Thanks in advance!

knubie15:03:14

Couple of things you can try in :compiler-options: :optimizations :simple and :infer-externs :auto

defa15:03:05

I have :compiler-options {:infer-externs :auto} but there is no hint to what I could change to make thinks work. As a workaround :optimizations :simple probably works but having :advanced compilation working is preferred.

defa15:03:28

tick depends on js-joda-time which is normally pulled in with cljsjs based deps… so my guess is, that js-joda.time* gets yanked by the compiler because they are not considered as used. Just an idea…

defa15:03:48

The device log shows the crash as:

--------- beginning of crash
2020-03-05 16:39:19.966 1894-1923/? E/AndroidRuntime: FATAL EXCEPTION: mqt_native_modules
    Process: , PID: 1894
    com.facebook.react.common.JavascriptException: TypeError: this.wh is not a function. (In 'this.wh()', 'this.wh' is undefined), stack:
    [email protected]:439247

thheller16:03:55

thats definitely caused by missing externs

thheller16:03:17

might just be missing externs in the tick library since :infer-externs :auto only warns about your sources

thheller16:03:42

one quick way to find out what that originally was is running shadow-cljs release app --pseudo-names and looking at the log

👍 4
thheller16:03:01

it'll be "`this.$someThing$` is undefined"

thheller16:03:15

then you edit externs/app.txt and add someThing (one line)

thheller16:03:17

that should fix it

defa16:03:48

Cool, thanks @U05224H0W will try later, when back at the keyboard...

defa17:03:24

Tried shadow-cljs release app --pseudo-names and only got one warning:

------ WARNING #1 -  -----------------------------------------------------------
 Resource: com/cognitect/transit/impl/writer.js:256:8
 variable isObject is undeclared
--------------------------------------------------------------------------------
nil
but nothing like “`this.$someThing$` is undefined”

defa17:03:08

However running shadow-cljs check app gives me tons of warnings (> 500) many related to the tick library:

------ WARNING #547 -  ---------------------------------------------------------
 File: ~/.m2/repository/tick/tick/0.4.23-alpha/tick-0.4.23-alpha.jar!/tick/core.cljc:1055:61
--------------------------------------------------------------------------------
1052 |   LocalDateTime
1053 |   (in [ldt z] (.atZone ldt z))
1054 |   (offset-by [ldt offset] #?(:clj (.atOffset ldt (zone-offset offset))
1055 |                              :cljs (.atZone ldt (zone-offset offset))))
-------------------------------------------------------------------^------------
 Property atZone never defined on ldt__$1
--------------------------------------------------------------------------------

thheller17:03:25

the error you get at runtime

thheller17:03:31

--------- beginning of crash
2020-03-05 16:39:19.966 1894-1923/? E/AndroidRuntime: FATAL EXCEPTION: mqt_native_modules
    Process: , PID: 1894
    com.facebook.react.common.JavascriptException: TypeError: this.wh is not a function. (In 'this.wh()', 'this.wh' is undefined), stack:
    [email protected]:439247

thheller17:03:33

this thing ...

thheller17:03:51

check unfortunately produces a lot of noise

defa17:03:07

Okay, sorry… thought with log you meant shadlow’s output.

thheller17:03:19

you can comb through those and those look like likely candidates

thheller17:03:31

you can also just include the tick externs it has by default if you want

defa17:03:58

Here we go, found the missing externs in the device log:

E/ReactNativeJS: TypeError: this.$toLocalDate$ is not a function. (In 'this.$toLocalDate$()', 'this.$toLocalDate$' is undefined)
… put it in externs/app.txt, rebuild the apk and now it no longer crashes. Thank you very much Sir!

defa17:03:39

Regarding tick’s “externs it has by default”, where would I find those? Didn’t find them in the repo?

thheller17:03:08

:compiler-options {:externs ["cljsjs/js-joda/common/js-joda.ext.js"]} in your build config

defa18:03:17

Of course! I looked for the externs in tick 🙈

defa18:03:20

So I guess adding thheller/shadow-cljsjs as a dependency would have fixed the problem as well?

thheller18:03:24

no that wouldn't have done anything

thheller18:03:37

it isn't related to this in any way

thheller18:03:59

(and shadow-cljs already depends on that anyways so it is always there ...)

michael.heuberger21:03:55

Morning. Has anyone ever managed to resolve npm dependencies installed by shadow-cljs in cursive? Cursive always displays these as “x cannot be resolved”. This because the npm dependencies are in package.json but not project.clj - Cursive seems to only scan those in project.clj. Thoughts?

👍 4
cfleming21:03:20

Sadly, this doesn’t work yet - it’s on my list to fix.

🎉 8
michael.heuberger21:03:30

@U0567Q30W is there a github ticket for that yet?

cfleming21:03:09

You know, I actually don’t think there is an issue for that - 1804 is different, that’s about integrating Shadow directly into Cursive.

cfleming21:03:16

If you could file an issue that would be great.