Fork me on GitHub
#shadow-cljs
<
2018-09-06
>
thheller07:09:48

@ghiden I recommend creating a wrapper function. (ns your.thing (:require ["react" :as react])) (defn create-element [...] (react/createElement ...))

thheller07:09:10

then use your.thing/create-element. Closure will optimize the extra wrapper fn away

ghiden07:09:17

@thheller thanks. I’ll try that approach.

thheller07:09:43

you can also use (def create-element react/createElement) if you don't care about the wrapping part

ghiden09:09:54

Just confirmed that it works! Thanks again! 👍

mitchelkuijpers09:09:08

I am running into:

failed to require :target :browser-test for build :test
CompilerException: java.lang.RuntimeException: Unable to resolve symbol: defelem in this context, compiling:(hiccup/page.clj:20:1)
        clojure.lang.Compiler.analyze (Compiler.java:6792)              
        clojure.lang.Compiler.analyze (Compiler.java:6729)                    
        clojure.lang.Compiler$InvokeExpr.parse (Compiler.java:3813)           
        clojure.lang.Compiler.analyzeSeq (Compiler.java:7005)                                                                                                                                                                             clojure.lang.Compiler.analyze (Compiler.java:6773)
        clojure.lang.Compiler.analyze (Compiler.java:6729)                                         
        clojure.lang.Compiler.eval (Compiler.java:7066)                                  
        clojure.lang.Compiler.load (Compiler.java:7514)                        
        clojure.lang.RT.loadResourceScript (RT.java:379)
        clojure.lang.RT.loadResourceScript (RT.java:370)
        clojure.lang.RT.load (RT.java:460)                                                                                                                                                                                       
        clojure.lang.RT.load (RT.java:426)                                                                  
        clojure.core/load/fn--6548 (core.clj:6046)                                  
        clojure.core/load (core.clj:6045)                                             
        clojure.core/load (core.clj:6029)                                                            
        clojure.core/load-one (core.clj:5848)                                                                                                                                                                                    
        clojure.core/load-one (core.clj:5843)                                                                   
        clojure.core/load-lib/fn--6493 (core.clj:5888)                        
        clojure.core/load-lib (core.clj:5887)                                     
        clojure.core/load-lib (core.clj:5868)             
        clojure.core/apply (core.clj:659)                                                          
        clojure.core/load-libs (core.clj:5925)                                           
        clojure.core/load-libs (core.clj:5909)                                 
        clojure.core/apply (core.clj:659)                   
        clojure.core/require (core.clj:5947)                                       
        clojure.core/require (core.clj:5947)                             
        shadow.build.targets.browser-test/eval91055/loading--6434--auto----91056 (browser_test.clj:1)
        shadow.build.targets.browser-test/eval91055 (browser_test.clj:1)
        shadow.build.targets.browser-test/eval91055 (browser_test.clj:1)      
        clojure.lang.Compiler.eval (Compiler.java:7062)                       
        clojure.lang.Compiler.eval (Compiler.java:7051)                                                                                                                                                                           
        clojure.lang.Compiler.load (Compiler.java:7514)
                                     
when trying to use browser-test, when I add hiccup it works again. So maybe you did some deps cleanup?

thheller09:09:34

@mitchelkuijpers there was a race-condition related to that. I fixed it a few versions ago though. which version are you on?

thheller09:09:48

I delayed loading all the web stuff so that is a) doesn't get AOT compiled and b) doesn't delay server startup

thheller09:09:20

but due to loading hiccup in a different thread you could end up trying to use it before it finished loading

thheller09:09:28

that you are seeing above

mitchelkuijpers09:09:16

I was trying out 2.6.6, but I just downgraded to 2.6.3

thheller09:09:39

hmm that should be fixes in 2.6.6 definitely. what command did you run?

mitchelkuijpers10:09:32

npx shadow-cljs watch test

mitchelkuijpers10:09:48

It was fixed when I added hiccup to my deps

thheller10:09:03

shadow-cljs depends on hiccup. that hasn't changed in forever.

thheller10:09:44

but as I said its a race condition so it is just a timing issue. if the build starts too fast you'll run into the problem again.

thheller10:09:52

I'll see why this is still happening

mitchelkuijpers10:09:00

Ah ok, that makes sense

mitchelkuijpers10:09:06

I am using tools.deps not sure if that helps

thheller11:09:48

you misinterpret the error. hiccup is definitely on the classpath regardless of you adding it or not. it is not a dependecy problem.

thheller11:09:38

its a race condition. shadow-cljs will load the hiccup namespace in another thread but due to how Clojure works the namespace will be immediately available

thheller11:09:06

so thread one will starting loading hiccup one form at a time starting with ns.

thheller11:09:27

the other thread has (:require [hiccup.core ...]) and clojure sees that the ns is already loaded

thheller11:09:41

despite the other thread still being in the process of loading the individual forms

thheller11:09:05

the other thread continues on. wants to use defelem but it isn't loaded yet and boom

mitchelkuijpers12:09:24

Ah ok, thank you for the explanation

basti15:09:17

when using the :node-test target how can I get the node process to connect to my REPL?

basti15:09:48

basically I’d like to have a REPL session where my test-code is already included

richiardiandrea16:09:21

@basti what I do is to have a separate :node-script target that requires all the test namespaces so that they are compiled. Not ideal I know, maybe @thheller has a better idea

thheller16:09:18

@basti :node-test disables all devtools since it supposed to exit after running the tests since we need the exit code for CI. is it not sufficient if you just use node-repl and manually load whichever test you are working on/want to run?

richiardiandrea18:09:57

Is node-repl compiling everything on the classpath independently? I think that is the problem I have noticed

thheller18:09:14

it doesn't compile anything unless you require it

basti18:09:00

manually loading would work but it’s tedious because I have to load all test dependencies, and If I required a library in my tests that hasn’t been required yet it’s missing

basti18:09:23

so I kinda end up requiring test dependencies in my production code to work around

thheller18:09:11

not sure I understand? your tests will require the code they need?

richiardiandrea19:09:01

so what @basti is saying is something I faced as well, and it basically made me do something like this in a separate entry point:

(ns my.registry.repl
  (:require [cljs.spec.alpha :as s]
            ;; so that we have the test compiled in the REPL
            [my.registry-test]
            [my.registry.aws-test]
            [my.registry.azure-test]))

basti19:09:21

yeah well explained @richiardiandrea! that’s what I was trying to say!

richiardiandrea19:09:08

if node-repl compiles everything independently from the entry point then it should be good

richiardiandrea19:09:24

otherwise the REPL would complain and you have to require in the REPL the namespace in order to "compile" it the first time, that is what I have experienced at least

thheller19:09:11

would complain about what?

thheller19:09:25

yes you have to require a ns before anything can be used

richiardiandrea20:09:53

yes and that is what I think we are both asking, if there is a way to have a node repl that automagically requires/compiles the test namespaces - without the glue file above

thheller20:09:13

not currently no

thheller20:09:58

but why do you need to require ALL? do you not use the REPL to work on ONE particular test/ns? why do the others need to be loaded?

richiardiandrea20:09:54

this might be true, but still, maybe metadata marker on the ns that tells node-test to preload that particular one ns would be convenient 😉

lilactown19:09:15

in the :browser-test target, if I use a custom runner-ns do I need to :require all of them test namespaces?

thheller19:09:09

only need to keep the init/start/stop fns

thheller19:09:17

everything else is optional

lilactown19:09:25

ah, I just found that file 😄 thanks!

thheller19:09:54

btw cljs-test-display looks real nice and I was thinking about using it by default

thheller19:09:57

just didn't get to it yet

lilactown19:09:48

yeah! I'm going to whip up a test runner for it. I can submit a PR when I'm done

lilactown20:09:46

was a change made to the type inference between 2.4.4 and 2.6.6? I'm running into https://dev.clojure.org/jira/browse/CLJS-1918 all of a sudden

lilactown20:09:57

tch. looks like it might be because I'm on an older CLJS version.

lilactown20:09:44

yep. just removing my overrides of CLJS and the closure compiler fixed it.