shadow-cljs

https://github.com/thheller/shadow-cljs | https://github.com/sponsors/thheller | https://www.patreon.com/thheller
kiranshila 2020-09-06T02:15:04.119Z

How do I get around Cannot infer target type in expression errors? The code compiles are first go, but it breaks hot-reloading. I'm trying to use web bluetooth.

kiranshila 2020-09-06T02:33:32.119900Z

I tried going the route of adding a node module that wraps web bluetooth, but I get compiler errors

[:app] Build failure:
Failed to inspect file
  <project>/node_modules/keypress/index.js

it was required from
  <project>/node_modules/node-web-bluetooth/src/InteractiveTermList.js

Errors encountered while trying to parse file
  <project>/node_modules/keypress/index.js
  {:line 374, :column 30, :message "Octal integer literals are not supported in strict mode."}
  {:line 375, :column 30, :message "Octal integer literals are not supported in strict mode."}

Jakub Holý 2020-09-06T07:21:43.122600Z

Based on the previous discussion, I guess that recompilation times of 2.3 - 3.8s during watch are also very high, correct? I have just tested running npx shadow-cljs watch :main --verbose in https://github.com/fulcrologic/fulcro-rad-demo/, forcing a recompilation by changing a string at line 57 of src/shared/com/example/ui/sales_report.cljc Detailed verbose output in the thread.

Jakub Holý 2020-09-07T11:48:44.142300Z

Thank you very much for trying this out on your machine! I have an early 2015 MacBook Pro with 16GB RAM (14GB used) and an SSD disk, which was a high-performance machine at that time but perhaps is too aged now. The OS complained about the disk being used but increasing the free space from 5 to 10GB did not change the performance. I guess I just need a new mchine...

thheller 2020-09-07T13:12:03.142600Z

I'm afraid its not the computer. I have pretty much the same machine. 2,5ghz i7 macback pro mid 2015. 16gb ram, ssd. recompile time is a bit slower but not much. about 0.69s

thheller 2020-09-07T13:16:40.142800Z

maybe your disk is just getting slow which can happen in SSDs over long time

thheller 2020-09-07T13:16:57.143Z

or more likely its something running on your machine interfering with stuff

thheller 2020-09-07T13:18:26.143200Z

-> Resolving Module: :main
<- Resolving Module: :main (24 ms)
-> build target: :browser stage: :compile-prepare
<- build target: :browser stage: :compile-prepare (0 ms)
-> Compile CLJS: com/example/ui/sales_report.cljc
-> Compile CLJS: com/example/ui/dashboard.cljc
<- Compile CLJS: com/example/ui/dashboard.cljc (11 ms)
-> Cache write: com/example/ui/dashboard.cljc
-> Compile CLJS: com/example/ui.cljc
<- Compile CLJS: com/example/ui/sales_report.cljc (62 ms)
-> Cache write: com/example/ui/sales_report.cljc
<- Compile CLJS: com/example/ui.cljc (66 ms)
-> Cache write: com/example/ui.cljc
<- Cache write: com/example/ui/dashboard.cljc (141 ms)
<- Cache write: com/example/ui/sales_report.cljc (134 ms)
<- Cache write: com/example/ui.cljc (158 ms)
-> build target: :browser stage: :compile-finish
<- build target: :browser stage: :compile-finish (9 ms)
-> build target: :browser stage: :flush
-> Flushing unoptimized modules
-> Flush: com/example/ui/sales_report.cljc
-> Flush: shadow/module/main/append.js
<- Flush: com/example/ui.cljc (1 ms)
<- Flush: com/example/ui/sales_report.cljc (1 ms)
<- Flushing unoptimized modules (177 ms)
<- build target: :browser stage: :flush (189 ms)
[:main] Build completed. (1012 files, 3 compiled, 0 warnings, 0.63s)

thheller 2020-09-07T13:18:38.143400Z

thats from my macbook, barely any difference

Jakub Holý 2020-09-07T16:08:19.143600Z

Thank you! I will do further experiments.

Jakub Holý 2020-09-06T07:22:31.122700Z

First recompile, 3.8s:

[:main] Compiling ...
-> Resolving Module: :main
<- Resolving Module: :main (83 ms)
-> build target: :browser stage: :compile-prepare
<- build target: :browser stage: :compile-prepare (0 ms)
-> Compile CLJS: com/example/ui/sales_report.cljc
-> Compile CLJS: com/example/ui/dashboard.cljc
-> Compile CLJS: com/example/ui.cljc
<- Compile CLJS: com/example/ui/dashboard.cljc (136 ms)
-> Cache write: com/example/ui/dashboard.cljc
<- Compile CLJS: com/example/ui/sales_report.cljc (518 ms)
-> Cache write: com/example/ui/sales_report.cljc
<- Compile CLJS: com/example/ui.cljc (457 ms)
-> Cache write: com/example/ui.cljc
<- Cache write: com/example/ui/dashboard.cljc (616 ms)
<- Cache write: com/example/ui/sales_report.cljc (753 ms)
<- Cache write: com/example/ui.cljc (1201 ms)
-> build target: :browser stage: :compile-finish
<- build target: :browser stage: :compile-finish (20 ms)
-> build target: :browser stage: :flush
-> Flush: com/example/ui.cljc
-> Flush: com/example/ui/dashboard.cljc
-> Flush: com/example/ui/sales_report.cljc
<- Flush: com/example/ui/dashboard.cljc (4 ms)
<- Flush: com/example/ui.cljc (11 ms)
<- Flush: com/example/ui/sales_report.cljc (17 ms)
-> Flushing unoptimized modules
-> Flush: shadow/module/main/append.js
<- Flush: shadow/module/main/append.js (2 ms)
<- Flushing unoptimized modules (1425 ms)
<- build target: :browser stage: :flush (1583 ms)
[:main] Build completed. (1014 files, 3 compiled, 0 warnings, 3.87s)
Second recompile, 2.3s:
[:main] Compiling ...
-> Resolving Module: :main
<- Resolving Module: :main (70 ms)
-> build target: :browser stage: :compile-prepare
<- build target: :browser stage: :compile-prepare (0 ms)
-> Compile CLJS: com/example/ui/sales_report.cljc
-> Compile CLJS: com/example/ui/dashboard.cljc
-> Compile CLJS: com/example/ui.cljc
<- Compile CLJS: com/example/ui/dashboard.cljc (53 ms)
-> Cache write: com/example/ui/dashboard.cljc
<- Compile CLJS: com/example/ui/sales_report.cljc (436 ms)
-> Cache write: com/example/ui/sales_report.cljc
<- Compile CLJS: com/example/ui.cljc (323 ms)
-> Cache write: com/example/ui.cljc
<- Cache write: com/example/ui/dashboard.cljc (593 ms)
<- Cache write: com/example/ui/sales_report.cljc (618 ms)
<- Cache write: com/example/ui.cljc (675 ms)
-> build target: :browser stage: :compile-finish
<- build target: :browser stage: :compile-finish (15 ms)
-> build target: :browser stage: :flush
-> Flushing unoptimized modules
-> Flush: com/example/ui/sales_report.cljc
-> Flush: com/example/ui/dashboard.cljc
<- Flush: com/example/ui/sales_report.cljc (10 ms)
-> Flush: com/example/ui.cljc
<- Flush: com/example/ui/dashboard.cljc (14 ms)
<- Flush: com/example/ui.cljc (7 ms)
-> Flush: shadow/module/main/append.js
<- Flush: shadow/module/main/append.js (0 ms)
<- Flushing unoptimized modules (756 ms)
<- build target: :browser stage: :flush (778 ms)
[:main] Build completed. (1014 files, 3 compiled, 0 warnings, 2.32s)

Jakub Holý 2020-09-06T07:23:04.122900Z

Is it simply because Fulcro is too macro-heavy and there is no way around it? Thank you for any hints!!!

thheller 2020-09-06T07:39:47.124Z

@me1310 https://shadow-cljs.github.io/docs/UsersGuide.html#externs likely just need one ^js hint in the correct location? or just turn it off if you don't care about release. :compiler-options {:infer-externs false}

👍 1
thheller 2020-09-06T07:42:20.124100Z

[:main] Build completed. (1014 files, 1013 compiled, 0 warnings, 48.54s)
[:main] Compiling ...
-> Resolving Module: :main
<- Resolving Module: :main (44 ms)
-> build target: :browser stage: :compile-prepare
<- build target: :browser stage: :compile-prepare (0 ms)
-> Compile CLJS: com/example/ui/sales_report.cljc
-> Compile CLJS: com/example/ui/dashboard.cljc
-> Compile CLJS: com/example/ui.cljc
<- Compile CLJS: com/example/ui/dashboard.cljc (20 ms)
-> Cache write: com/example/ui/dashboard.cljc
<- Compile CLJS: com/example/ui/sales_report.cljc (82 ms)
-> Cache write: com/example/ui/sales_report.cljc
<- Compile CLJS: com/example/ui.cljc (78 ms)
-> Cache write: com/example/ui.cljc
<- Cache write: com/example/ui/dashboard.cljc (174 ms)
<- Cache write: com/example/ui/sales_report.cljc (173 ms)
<- Cache write: com/example/ui.cljc (216 ms)
-> build target: :browser stage: :compile-finish
<- build target: :browser stage: :compile-finish (8 ms)
-> build target: :browser stage: :flush
-> Flushing unoptimized modules
-> Flush: com/example/ui/sales_report.cljc
-> Flush: com/example/ui.cljc
-> Flush: shadow/module/main/append.js
<- Flush: shadow/module/main/append.js (5 ms)
<- Flush: com/example/ui.cljc (22 ms)
<- Flush: com/example/ui/dashboard.cljc (28 ms)
<- Flush: com/example/ui/sales_report.cljc (38 ms)
<- Flushing unoptimized modules (133 ms)
<- build target: :browser stage: :flush (150 ms)
[:main] Build completed. (1014 files, 3 compiled, 0 warnings, 0.68s)

thheller 2020-09-06T07:43:44.124300Z

[:main] Build completed. (1014 files, 3 compiled, 0 warnings, 0.56s)

thheller 2020-09-06T07:44:29.124500Z

averages out around that area on my machine which is very fast so I don't know if its just a hardware difference or maybe something else going on

thheller 2020-09-06T07:44:34.124700Z

what kind of system are you on?

thheller 2020-09-06T07:45:31.124900Z

maybe your harddisk is almost full or something?

Jakub Holý 2020-09-06T14:56:41.125100Z

Osx. Perhaps the disk, I will check. Thank you very much!

kiranshila 2020-09-06T16:51:28.125600Z

Right, of course. Thanks so much!

kiranshila 2020-09-06T18:32:31.125800Z

What does it mean if it still can't infer the target type, even with the type hint?

kiranshila 2020-09-06T18:33:28.126Z

I have the following in a go-loop, but I still get an error

(<p! (.writeValue ^js sock chunk))

kiranshila 2020-09-06T18:33:35.126200Z

Cannot infer target type in expression (. inst_48442 (writeValue inst_48443))

kiranshila 2020-09-06T18:34:00.126400Z

that sock value is the result of de-refing an atom

thheller 2020-09-06T18:50:24.126600Z

ah you are in core.async go. that appears to be loosing typehints

kiranshila 2020-09-06T18:50:44.126800Z

Oh interesting

thheller 2020-09-06T18:50:47.127Z

if you have the sock outside the go then annotate it there

kiranshila 2020-09-06T18:57:46.128400Z

Perfect. Thank you!

adamrenklint 2020-09-06T19:48:46.129600Z

Is it possible to trigger the :after-load fn of a :target :browser build from the :flush hook of a :target :bootstrap build?

2020-09-06T20:21:41.132600Z

Might anyone know why a macro that pulls in a symbol would cause “Use of undeclared Var” errors? i.e. a macro like

(ns a-ns
  (:require [some.namespace :as sn]))

(defmacro something []
  (sn/some-function "do a thing"))
… when used in another namespace seems to sporadically give me:
(ns another-ns)

(something) ;=> Use of undeclared Var some.namespace/some-function
Which is resolved by doing (:require [some.namespace]) at the use site of the macro… but this hasn’t usually been necessary and the issue goes away from time to time. This seems like it might be new behavior (I’m using 2.10.22), but that could be due to mutations in my own codebase. Would really welcome any thoughts on this, I’ve tried debugging and poking around a bunch to no reliable discovery of the pattern causing the issue so far 🙂

2020-09-06T20:28:17.135300Z

ah I think this is because I’m doing CLJC self-require - i.e. (ns app.util #?(:cljs (:require-macros [app.util]))

2020-09-06T20:28:53.136100Z

oh hm no, I’m following the separate ns pattern here

thheller 2020-09-06T20:28:56.136300Z

CLJC makes this 10x more complicated but it is fine if you do it correctly

2020-09-06T20:29:06.136700Z

I’ll pick through and check I’m doing every step right

2020-09-06T20:29:17.137200Z

thanks!

thheller 2020-09-06T20:29:18.137300Z

the example code you posted is incomplete so I cannot say where maybe you went wrong

2020-09-06T20:29:22.137500Z

👍

2020-09-06T20:31:29.137800Z

okay, I think that helped rebase/realign my understanding and I believe I’ve resolved it now — thanks so much for the prompt! 🙂