Fork me on GitHub
#shadow-cljs
<
2020-04-23
>
yenda08:04:11

I'm trying to js/require a json but I can't figure out which path the js/require is starting at, how can I find out?

yenda08:04:40

mhm maybe it doesn't make sense looks like I got the path right as it works for images, for instance (js/require "../resources/images/ui/welcome.jpg") works but (js/require "../resources/images/ui/fleets.json") doesn't

Spaceman09:04:14

I'm unable to load the kaocha repl using (use 'kaocha.repl) in my shadow-cljs repl. I have added it in the dependencies like so:

:dependencies [[lambdaisland/kaocha "1.0-612"]]
But upon doing (use 'kaocha.repl), I get:
Error in phase :compilation
Only [lib.ns :only (names)] and optionally `:rename {from to}` specs supported in :use / :use-macros; offending spec: [kaocha.repl] at line 1 cljs/user.cljs
Why is this?

thheller10:04:24

kaocha is not supported currently

thheller10:04:18

also the (use 'kaocha.repl) are instructions for CLJ not CLJS

Spaceman10:04:05

@thheller what's a good way to automate tests with shadow and maybe cider?

thheller10:04:48

no clue. I don't use tests in CLJS.

Spaceman12:04:43

Why not? Have you ever tried?

thheller15:04:09

just not into testing that much. mostly do stuff with the REPL and then sometimes write a test to automate

emil0r11:04:19

@thheller I’ve got a css generated from outside the directory of where I’m working using SASS. The generation works fine, but shadow-cljs does not reload. When I manually edit the generated CSS file shadow-cljs reloads. Any idea on how to solve this?

thheller11:04:24

you mean if you edit the generated file it reloads but it doesn't reload when it is generated?

thheller11:04:45

weird, no idea

thheller11:04:49

what do you use to generate?

thheller11:04:57

check if the file last-modified timestamp is changed when that generates a new file?

emil0r11:04:37

It updates, but to two hours back in time

thheller11:04:42

hmm might be that shadow-cljs uses the wrong check?

thheller11:04:53

usually it should just check (not= last-mod prev-mod)

thheller11:04:08

not (> last-mod prev-mod)

emil0r11:04:59

Hmm.. seems like gulp sets the last-modified timestamp to UTC+0

emil0r11:04:05

I’m currently at UTC+2

thheller11:04:05

it should be enough if it changes, which direction it changes shouldn't matter

thheller11:04:29

hmm yeah dunno. might be something internal from the filewatcher that it doesn't like things going back in time?

thheller11:04:34

shadow-cljs doesn't care

thheller11:04:54

just teach gulp to set the correct date 😉

emil0r11:04:56

Is there a trigger based on changed files?

emil0r11:04:15

Ie, a notify from a java api

thheller11:04:33

which OS do you use?

emil0r11:04:35

If so, could be that one that doesn’t report a changed file since it’s backwards in time. Ie, a previous version?

emil0r11:04:55

hmm… shouldn’t matter though

thheller11:04:03

macos uses the hawk library to watch fs changes

thheller11:04:08

linux/win do not

thheller11:04:34

dunno about hawk

emil0r11:04:46

That did the trick

emil0r11:04:55

So weird though

Niclas15:04:32

I have a RN app with minimal shadow-cljs config and it compiles as I expect. Auto load is not working however and I’m not sure where to look, does anybody have any ideas?

# shadow-cljs.edn
{
 ...
 :builds {:dev {:target     :react-native
                :init-fn    env.main/main
                :output-dir "target/dev"
                :devtools   {:autoload true
                            :after-load my.core/print-debug-stmt}
 ...
}

Niclas15:04:06

Running shadow-cljs v2.8.99 with npx shadow-cljs watch :dev

thheller15:04:38

is this my.core/print-debug-stmt maybe not included in the regular build?

thheller15:04:07

may need to add :preloads [my.core] into :devtools so the ns is actually compiled?

Niclas16:04:10

@thheller It’s included in the regular build, it’s actually the fn that registers the root app component but I just changed names for it here 😄

Niclas16:04:23

Tried adding the ns to :preloads with no change

thheller16:04:15

react-native is not capable of hot-reloading the root components once registered

thheller16:04:25

so the registerComponent call can only be done once

Niclas16:04:28

Thanks, I’ll try that out

Niclas17:04:06

@thheller Unfortunately, no success

Niclas17:04:03

I even tried putting (println "ABC") in the top level of my.core that’s printed only the first time the app is loaded but not after edits and recompiles

thheller17:04:42

any build warnings?

Niclas17:04:33

None to speak of

Niclas17:04:42

I get this occasionalyl in the terminal, maybe it’s connected?

Niclas17:04:47

Exception in thread "async-dispatch-9" java.lang.IllegalArgumentException: No implementation of method: :close! of protocol: #'clojure.core.async.impl.protocols/Channel found for class: clojure.lang.PersistentArrayMap
	at clojure.core$_cache_protocol_fn.invokeStatic(core_deftype.clj:583)
	at clojure.core$_cache_protocol_fn.invoke(core_deftype.clj:575)
	at clojure.core.async.impl.protocols$eval256$fn__257$G__245__262.invoke(protocols.clj:21)
...

Niclas17:04:07

Where I’ve run npx shadow-cljs watch :dev

thheller17:04:34

ah. tahts not normal

Niclas17:04:49

Good! 😄

thheller17:04:52

looks like you might have a bad core.async version?

Niclas17:04:58

I’ll check it out

Niclas17:04:11

[org.clojure/core.async "0.3.442"]

thheller17:04:20

yeah thats really bad

thheller17:04:25

[org.clojure/core.async "1.1.587"]

thheller17:04:35

or none at all if you are just using shadow-cljs.edn

Niclas17:04:01

Awesome, I’ll see if it works when I remove the dep

Niclas17:04:00

No luck there either I’m afraid

Niclas17:04:12

The crashes seem to have stopped though!

Niclas17:04:19

These are my deps

:dependencies [[binaryage/devtools "1.0.0"]
                [com.andrewmcveigh/cljs-time "0.5.2"]
                [com.cognitect/transit-cljs "0.8.256"]
                [com.rpl/specter "0.13.1"]
                [cljsjs/libphonenumber "8.10.18-0"]
                [orchestra "2017.07.04-1"]
                [expound "0.5.0"]
                [org.clojure/test.check "0.9.0" :scope "test"]
                [pjstadig/humane-test-output "0.8.1" :scope "test"]
                [re-frame "0.11.0-rc3"]
                [reagent "0.9.0-rc4" :exclusions [cljsjs/react-dom
                                                  cljsjs/react
                                                  cljsjs/react-dom-server
                                                  cljsjs/create-react-class]]
                [day8.re-frame/test "0.1.5" :scope "test"]]

Niclas17:04:34

Do you think there might be some other collission in deps?

thheller17:04:59

expound is also really old

Niclas17:04:43

Updated it to latest 0.8.4 without results 😞

thheller17:04:18

dunno. what does the device log have to say? likely that it just fails to connect to the shadow-cljs server? happens if it can't find the correct IP to use?

Niclas17:04:33

That could be it, it does do the first load at least

Niclas17:04:41

And I can see that index.js updates as expected

Niclas17:04:20

Are there any shadow-cljs specific logs I could look at?

thheller17:04:49

did you turn off the built-in react-native reloading?

thheller17:04:44

what do you mean by "index.js updates as expected"?

Niclas17:04:26

I add a line (println "something-new") and can see that "something-new" appears in index.js 😄

thheller17:04:05

yeah .. compilation works

thheller17:04:15

that doesn't mean that the device was able to connect to shadow-cljs

thheller17:04:19

look at the device log

Niclas17:04:39

Ah, I’ll have a look

Niclas17:04:13

Not getting any device logs when recompiling, do you want me to look for anything special in the logs that are printed on startup? I can’t find anything interesting but maybe I’m missing something

thheller17:04:39

it should log something like shadow-cljs - websocket connected

thheller17:04:59

or some kind of connect error

Niclas17:04:01

Ah! I can’t find that 😄

Niclas17:04:07

No matches for shadow

thheller17:04:09

not when compiling, when the app is first loaded

Niclas17:04:31

Not printed anywhere

thheller17:04:04

were the dependencies you listed from project.clj or shadow-cljs.edn?

Niclas17:04:31

From shadow-cljs.edn

thheller17:04:59

try shadow-cljs watch dev --verbose

thheller17:04:09

if should log the IP it is trying to connect to

thheller17:04:21

maybe thats just incorrect or taking a long time to time out

Niclas17:04:14

It does log Using IP: 192.168.1.208

thheller17:04:14

and is that the correct one?

Niclas17:04:48

That is my IP on the local network, is that what’s correct?

thheller17:04:50

I mean can you open http://192.168.1.208:9630 on your device browser?

thheller17:04:07

if your phone is on that same network yes

Niclas17:04:27

I’m running on simulator atm

Niclas17:04:36

This is what I see

thheller17:04:09

yeah thats fine

thheller17:04:16

then I really don't know

thheller17:04:32

the first thing this should be doing is connect to the shadow-cljs websocket

thheller17:04:41

without that connection it won't know what it should reload etc

Niclas17:04:59

Simulator can reach it too

thheller17:04:01

I don't do react-native myself so you'll have to figure this out on your own

Niclas17:04:24

Bummer, but thanks for the help!

Niclas17:04:47

This project has been running on for almost 4 years now so there’s likely a bunch of old dependencies and setup that might get in the way

Niclas17:04:39

Was really stoked though to switch from figwheel to shadow though 😄

Patrick Truong16:04:21

Hello everyone, I’m new to shadow-cljs and ClojureScript. I was curious if there is a command that audits your dependencies for new available releases, and if there’s a command to update dependencies as well? Thanks for all the help!

thheller16:04:50

there is not (yet) a command for that no if you are using shadow-cljs.edn only. lein or deps.edn have options for that.

👍 4
👀 4
Derek16:04:15

npx npm-check -u for npm deps

Derek16:04:36

if you’re using deps.edn

Derek16:04:40

lein-ancient if lein

Patrick Truong16:04:29

Question for anybody who uses cljs-devtools (https://github.com/binaryage/cljs-devtools) I just added it to my basic reagent/re-frame project deps.edn

{:paths ["src"]
 :deps  {thheller/shadow-cljs {:mvn/version "2.8.94"}
         binaryage/devtools   {:mvn/version "1.0.0"}
         reagent              {:mvn/version "0.10.0"}
         re-frame             {:mvn/version "0.12.0"}}}
shadow-cljs.edn
{:deps   true
 :builds {:app {:target     :browser
                :output-dir "public/out"
                :modules    {:app {:entries []
                                   :init-fn 
                :devtools   {:http-root "public"
                             :http-port 8020}}}}
and now I’m getting a bunch of console warnings along with my page no longer rendering
failed to load shadow.module.app.append.js TypeError: alpha_journal.app.render is not a function
    at Object.alpha_journal$app$main [as main] (:8020/js/cljs-runtime/alpha_journal.app.js:15)
    at eval (:8020/js/cljs-runtime/shadow.module.app.append.js:4)
    at eval (<anonymous>)
    at Object.goog.globalEval (app.js:836)
    at Object.env.evalLoad (app.js:2224)
    at app.js:2414
DevTools failed to parse SourceMap: 
...
I was following the cljs-devtools example (https://github.com/binaryage/cljs-devtools/tree/master/examples/shadow) for shadow-cljs and it seems like I didn’t need to explicitly set a :preloads or anything. Thanks for any help 🙂

thheller16:04:59

check the first error? alpha_journal.app.render is not a function this is likely the result of something else failing before it

Patrick Truong16:04:39

@thheller :face_palm: thanks, accidentally slurped my render function into another function. That fixed my rendering issue, but now I’m still getting the sourcemap parsing failures:

DevTools failed to parse SourceMap: 
DevTools failed to parse SourceMap: 
DevTools failed to parse SourceMap: 
DevTools failed to parse SourceMap: 
DevTools failed to parse SourceMap: 
DevTools failed to parse SourceMap: 
...
I didn’t explicitly require any DevTools package in my main file. Is that a possible problem? app.cljs
(ns 
  (:require
   [reagent.core :as r]
   [reagent.dom :as dom]))

thheller16:04:18

no you shouldn't have a direct require for it anywhere. thats already taken care of just by including it in your dependencies

thheller16:04:52

is the path correct? I mean what do you get when you open http://localhost:8020/js/cljs-runtime/goog.debug.error.js.map manually?

Patrick Truong16:04:33

I get a blank page and console output as:

Failed to load resource: the server responded with a status of 404 (Not Found)
app.js:1 Failed to load resource: the server responded with a status of 404 (Not Found)
app.css:1 Failed to load resource: the server responded with a status of 404 (Not Found)
DevTools failed to parse SourceMap: 
DevTools failed to parse SourceMap: 

thheller17:04:36

so its not the correct path?

thheller17:04:40

where is your output?

Patrick Truong17:04:08

Sorry I’m a bit lost on the path situation. I’m seeing my page render on http://localhost:8020/, but if I follow the sourcemap warning link (ex. http://localhost:8020/js/cljs-runtime/goog.async.workqueue.js.map) I get a blank page and in the console, I get that output that I wrote above

thheller17:04:34

what is your :output-dir? what is your :asset-path? what is the path you are loading your JS from in your HTML?

Patrick Truong17:04:12

Hmm don’t believe I have those explicitly set. This is my shadow-cljs.edn

{:deps   true
 :builds {:app {:target     :browser
                :output-dir "public/out"
                :modules    {:app {:entries []
                                   :init-fn 
                :devtools   {:http-root "public"
                             :http-port 8020}}}}
and my index page is loading from <script _src_="out/app.js" _type_="text/javascript"></script> which I believe is correct

thheller17:04:38

so you need to add :asset-path "/out" (right after :output-dir) since that defaults to /js

thheller17:04:12

you can skip :entries [] since :init-fn already implies that

Patrick Truong17:04:38

Awesome, so if I understand correctly, when I have a custom :output-dir I should remember to set my :asset-path (otherwise it uses the default path which is wrong) That seemed to clear up most of my sourcemap warnings. I just have a preload and postload warning?

thheller17:04:39

don't know what those are? are you working on a browser extension? those errors come from a browser extension?

Patrick Truong17:04:07

Got it. Turned out Adblocker causes those warnings. If anyone else runs into the same thing, I just removed my adblocker extension.

Patrick Truong17:04:35

@thheller thanks for all the help! Much appreciated 🙂 I was curious though if you could elaborate a bit on what :entries does. Some of the config keys have been confusing me since I’ve been following a lot of tutorials and examples but a lot of them have very different config layouts in their shadow-cljs.edn. Thanks!

thheller17:04:16

entries is the namespaces that should be included in the module (your build basically)

thheller17:04:54

:init-fn basically is sugar for :entries [] and calling the main fn on load

thheller17:04:04

you can keep it but it is redundant

Patrick Truong17:04:38

Awesome, thanks for the clarification. Helps a lot

Andrea Russo17:04:31

is there a way to import a cljs library from a github repo instead of a maven repo? I need to patch the https://github.com/ckirkendall/kioo library

lilactown17:04:00

if you use deps.edn, it’s fairly easy

lilactown17:04:12

requires moving your dependencies from shadow-cljs.edn to a deps.edn

lilactown17:04:35

alternatively, you can copy + paste the kioo source files into your project

thheller17:04:26

@lilactown deps.edn won't work. the lib has no deps.edn.

lilactown17:04:18

you’re right, I didn’t think of that. if they’re forking it anyway, it’s easy to add one

Andrea Russo20:04:52

I use lein project.clj and shadow-cljs.edn