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.
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."}
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.
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...
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
maybe your disk is just getting slow which can happen in SSDs over long time
or more likely its something running on your machine interfering with stuff
-> 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)
thats from my macbook, barely any difference
Thank you! I will do further experiments.
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)
Is it simply because Fulcro is too macro-heavy and there is no way around it? Thank you for any hints!!!
@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}
[: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)
[:main] Build completed. (1014 files, 3 compiled, 0 warnings, 0.56s)
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
what kind of system are you on?
maybe your harddisk is almost full or something?
Osx. Perhaps the disk, I will check. Thank you very much!
Right, of course. Thanks so much!
What does it mean if it still can't infer the target type, even with the type hint?
I have the following in a go-loop, but I still get an error
(<p! (.writeValue ^js sock chunk))
Cannot infer target type in expression (. inst_48442 (writeValue inst_48443))
that sock
value is the result of de-refing an atom
ah you are in core.async go. that appears to be loosing typehints
Oh interesting
if you have the sock
outside the go
then annotate it there
Perfect. Thank you!
Is it possible to trigger the :after-load
fn of a :target :browser
build from the :flush
hook of a :target :bootstrap
build?
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 🙂@tekacs follow https://code.thheller.com/blog/shadow-cljs/2019/10/12/clojurescript-macros.html
ah I think this is because I’m doing CLJC self-require - i.e. (ns app.util #?(:cljs (:require-macros [app.util]))
oh hm no, I’m following the separate ns pattern here
CLJC makes this 10x more complicated but it is fine if you do it correctly
I’ll pick through and check I’m doing every step right
thanks!
the example code you posted is incomplete so I cannot say where maybe you went wrong
👍
okay, I think that helped rebase/realign my understanding and I believe I’ve resolved it now — thanks so much for the prompt! 🙂