Fork me on GitHub
#shadow-cljs
<
2020-09-06
>
kiranshila02:09:04

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.

kiranshila02:09:32

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ý (HolyJak)07:09:43

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ý (HolyJak)07:09:31

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ý (HolyJak)07:09:04

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

thheller07:09:20

[: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)

thheller07:09:44

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

thheller07:09:29

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

thheller07:09:34

what kind of system are you on?

thheller07:09:31

maybe your harddisk is almost full or something?

Jakub Holý (HolyJak)14:09:41

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

Jakub Holý (HolyJak)11:09:44

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...

thheller13:09:03

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

thheller13:09:40

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

thheller13:09:57

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

thheller13:09:26

-> 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)

thheller13:09:38

thats from my macbook, barely any difference

Jakub Holý (HolyJak)16:09:19

Thank you! I will do further experiments.

thheller07:09:47

@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}

👍 3
kiranshila16:09:28

Right, of course. Thanks so much!

kiranshila18:09:31

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

kiranshila18:09:28

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

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

kiranshila18:09:35

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

kiranshila18:09:00

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

thheller18:09:24

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

kiranshila18:09:44

Oh interesting

thheller18:09:47

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

kiranshila18:09:46

Perfect. Thank you!

adamrenklint19:09:46

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

tekacs20:09:41

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 🙂

tekacs20:09:17

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

tekacs20:09:53

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

thheller20:09:56

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

tekacs20:09:06

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

thheller20:09:18

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

tekacs20:09:29

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