Fork me on GitHub
#shadow-cljs
<
2019-02-01
>
austinbirch17:02:32

Hello, Wondering if anyone can help me with a NodeJS + CLJS setup. I’ve got an app already written in CLJS for the browser, but there’s some code in there I want to share with an already written NodeJS server app. My plan is to separate out the shared code into its own library; using shadow-cljs :node-library target to be able to build a JS version for use on the NodeJS server, and pull the library into the CLJS browser app as a normal CLJS dependency. Does that sound sensible? The next question I have after having trying the above is: when I’m developing this library, how can I get live reloading / REPL based workflow with a :node-library target? I’ve tried running the shadow-cljs watcher in one terminal, calling node ./dist/lib.js and then shadow-cljs cljs-repl lib to connect a CLJS repl but live reload doesn’t seem to pick up changes after file save (but I can get changes if I eval the code changes within the REPL).

thheller17:02:29

@austinbirch live-reload is a bit more restricted in node-library since we can't modify things after they were exported

thheller17:02:49

so live-reload from within CLJS should work but if you the stuff loaded from node can't

thheller17:02:07

but it should work depending on what you do. may need to manually enable it though :devtools {:autoload true}

thheller17:02:19

(if you don't have other hooks configured, eg. :after-load)

austinbirch17:02:10

Ah, I should have also mentioned that I set :devtools {:autoload true} and had live reloading working with :node-script (but then this isn’t consumable as a npm dependency). Maybe I should just create a :node-script build for development and a :node-library build for release?

thheller17:02:54

I wouldn't recommend that. you want your dev build to be as close as possible to release

thheller17:02:05

otherwise you'll end up debugging release builds endlessly 😛

austinbirch17:02:26

Yes (been there…!)

thheller17:02:25

but live-reload should work fine in node

thheller17:02:34

just the exports themselves can't be reloaded

lilactown17:02:39

is your NodeJS service written in JS?

austinbirch17:02:04

I actually might have been testing by updating the exported function, so maybe that’s it. If I export functionA that calls functionB, update functionB and save the file, would you expect that the live reload would run the new functionB?

austinbirch17:02:22

@lilactown existing project written in JS

👍 5
thheller17:02:05

yes that should work

austinbirch17:02:32

I will try now and get back to you. Thanks so much for all the help!

thheller17:02:17

var x = require("your-cljs.js"); x.foo();

thheller17:02:26

the foo can't be updated

thheller17:02:49

since node saves that references internally

thheller17:02:17

but whatever that foo calls internally can be updated normally

austinbirch17:02:03

Just tried and that’s working perfectly now. Very pleased!

austinbirch17:02:17

Thanks again for your help.

austinbirch17:02:04

When I was testing I’m pretty sure I had something like:

(defn exported-fn
  []
  "returning 1")
and was just updating the string to see live reloading work. So your explanation above makes perfect sense. Easy for me to just have the exported function call others in the CLJS namespace and work from there.

thheller17:02:29

yeah I tried making the exports dynamic once but it had a bunch of issues so I opted out of that

austinbirch17:02:07

Makes sense. I better get back to actually writing the code now then 🙂

colinkahn18:02:38

Can you have browser tests that autorun on changes?

colinkahn18:02:18

I see that it runs shadow-cljs: call shadow.test.browser/start when the code reloads, but this doesn't seem to actually update the UI with new tests

thheller18:02:43

just tested and works fine here.

colinkahn18:02:30

weird, any suggestions to help debug?

colinkahn18:02:59

cli version: 2.7.24 node: v8.9.4

thheller18:02:09

server version?

colinkahn18:02:21

server version: 2.7.24

thheller18:02:45

hmm yeah thats what i just tested with

colinkahn18:02:49

Actually, I just found it

colinkahn18:02:09

I was running it in the Brave browser and it wasn't working, works fine in Chrome

thheller18:02:32

hmm ok. don't have brave installed

thheller18:02:34

maybe it doesn't like the notifications?

colinkahn18:02:37

my assumption is its some security thing perhaps

colinkahn18:02:57

it will ask if I want to receive notifications

thheller18:02:06

try :closure-defines {cljs-test-display.core/notifications false}

thheller18:02:44

not sure. gotta go.

colinkahn18:02:51

no worries, i'll try that

colinkahn18:02:26

oh nice, that did work, thanks!

colinkahn18:02:25

Ah, actually no, that wasn't specifically my issue, it is that if I add a new test with deftest that test isn't run, regardless of whether it's Brave or Chrome

ccann18:02:25

can anyone recommend getting started with https://github.com/minimal-xyz/minimal-shadow-cljs-browser versus the shadow-cljs lein template?

ccann20:02:01

thank you

thheller20:02:17

they are all pretty similar though. so its really up to you

ccann20:02:22

:thumbsup:

ccann20:02:51

I know this isn’t necessarily a beginner forum, but whenever I kill my repls and then restart (via cider-connect-clj&cljs -> shadow -> app) I get Stale Client! in the browser window … which goes away if I hard-refresh the page

thheller20:02:10

@ccann this is absolutely a beginner forum 🙂 unfotrunately I can't help with cider issues as I know nothing about that

thheller20:02:32

stale client is the message you get when you load js that was not compiled by the current watch

ccann20:02:38

it seems to work anyway 🙂

thheller20:02:51

depending on which server you use it may be a cache issue

ccann20:02:59

okay interesting, thanks!

souenzzo21:02:13

I'm trying to move a figwheel project to shadow, but when I run (server/start!) I get:

Execution error (NoSuchFieldError) at shadow.build.closure.JsInspector/getFileInfo (JsInspector.java:161).
PARSE_RESULTS

thheller21:02:10

@souenzzo likely a bad version of the closure compiler on the classpath

👍 5
thheller21:02:57

should be [com.google.javascript/closure-compiler-unshaded "v20181125"] or later