Fork me on GitHub
#shadow-cljs
<
2021-03-26
>
Volodymyr Huzar13:03:17

We have :ssl in our configuration which enabling https for all builds. Is it possible to run :devtools for one of the build on http? To add more context: I am trying to run tests using https://github.com/lambdaisland/kaocha-cljs2 and having https there adding a lot of overhead to setup all the tools to have proper certificates provided everywhere. Also Chrome complains with registering custom ServiceWorkers when self signed certificates are used which seems to be configurable but again adds another overhead.

thheller17:03:41

@vguzar in 2.11.26 I added an option to allow that. :dev-http {3000 {:root "public" :ssl false}}

Volodymyr Huzar18:03:20

@U05224H0W seems it will not fix a problem I have. A :dev-http is a global configuration, isn’t? What I need to run one of the builds (test one) on http, but I want application build still to be run using https. Is it possible to solve somehow, maybe disable ssl using :devtools configuration?

thheller18:03:14

the http servers are ALWAYS global, the :devtools :http-root and :http-port are old configuration and were replaced by :dev-http

thheller18:03:54

so if you previously had :devtools {:http-port 3000 :http-root "public"} that should instead be :dev-http {3000 "public"} or the the example above with the disabled :ssl

Volodymyr Huzar18:03:45

oh, good to know that, doesn’t it complicates the things? how to serve different roots for different builds now?

thheller18:03:50

no, it makes things much simpler. it was my mistake allowing the devtools http config in a config for the build. that was never how it worked and the dev-http matches more closely how it actually works

thheller18:03:01

if you need multiple servers you just use multiple ports

thheller18:03:14

:dev-http {3000 {:root "public" :ssl false} 3001 "something-else"}

Volodymyr Huzar18:03:29

by the way the latest release I see here https://github.com/thheller/shadow-cljs/releases is 2.11.13

Volodymyr Huzar18:03:17

thanks a lot! everything, works as expected now

👍 1
haywood17:03:07

apologies… but has anyone run into this? I’m dusting off a project that hasn’t been touched in like a year

[:failed-to-compare "^16.13.1" "16.9.0" #error {
 :cause "Cannot invoke \"Object.getClass()\" because \"target\" is null"
 :via
 [{:type java.lang.NullPointerException
   :message "Cannot invoke \"Object.getClass()\" because \"target\" is null"
   :at [clojure.lang.Reflector invokeInstanceMethod "Reflector.java" 97]}]
 :trace
 [[clojure.lang.Reflector invokeInstanceMethod "Reflector.java" 97]
  [shadow.cljs.devtools.server.npm_deps$make_engine invokeStatic "npm_deps.clj" 39]
  [shadow.cljs.devtools.server.npm_deps$make_engine invoke "npm_deps.clj" 32]
  [shadow.cljs.devtools.server.npm_deps$fn__17458$fn__17459 invoke "npm_deps.clj" 46]
  [clojure.lang.Delay deref "Delay.java" 42]
  [clojure.core$deref invokeStatic "core.clj" 2320]
  [clojure.core$deref invoke "core.clj" 2306]
  [shadow.cljs.devtools.server.npm_deps$fn__17458$fn__17461 invoke "npm_deps.clj" 52]
  [shadow.cljs.devtools.server.npm_deps$is_installed_QMARK_ invokeStatic "npm_deps.clj" 207]
  [shadow.cljs.devtools.server.npm_deps$is_installed_QMARK_ invoke "npm_deps.clj" 201]
  [shadow.cljs.devtools.server.npm_deps$main$fn__17546 invoke "npm_deps.clj" 223]
  [clojure.core$complement$fn__5669 invoke "core.clj" 1441]
  [clojure.core$filter$fn__5893 invoke "core.clj" 2821]
  [clojure.lang.LazySeq sval "LazySeq.java" 42]
  [clojure.lang.LazySeq seq "LazySeq.java" 51]
  [clojure.lang.RT seq "RT.java" 535]
  [clojure.core$seq__5402 invokeStatic "core.clj" 137]
  [clojure.core$seq__5402 invoke "core.clj" 137]
  [shadow.cljs.devtools.server.npm_deps$main invokeStatic "npm_deps.clj" 225]
  [shadow.cljs.devtools.server.npm_deps$main invoke "npm_deps.clj" 216]
  [shadow.cljs.devtools.cli$main invokeStatic "cli.clj" 143]
  [shadow.cljs.devtools.cli$main doInvoke "cli.clj" 134]
  [clojure.lang.RestFn applyTo "RestFn.java" 137]
  [clojure.core$apply invokeStatic "core.clj" 669]
  [clojure.core$apply invoke "core.clj" 660]
  [shadow.cljs.devtools.cli$_main invokeStatic "cli.clj" 221]
  [shadow.cljs.devtools.cli$_main doInvoke "cli.clj" 219]
  [clojure.lang.RestFn applyTo "RestFn.java" 137]
  [clojure.lang.Var applyTo "Var.java" 705]
  [clojure.core$apply invokeStatic "core.clj" 665]
  [clojure.main$main_opt invokeStatic "main.clj" 514]
  [clojure.main$main_opt invoke "main.clj" 510]
  [clojure.main$main invokeStatic "main.clj" 664]
  [clojure.main$main doInvoke "main.clj" 616]
  [clojure.lang.RestFn applyTo "RestFn.java" 137]
  [clojure.lang.Var applyTo "Var.java" 705]
  [clojure.main main "main.java" 40]]}]

haywood17:03:35

versions:

=== Version
jar:            2.11.25
cli:            2.11.25
deps:           1.3.2
config-version: 2.11.25

thheller17:03:17

@haywood looks like you upgraded to java JDK 15+ in the meantime? that removed the Nashorn JS engine previously used. need to upgrade shadow-cljs.

thheller17:03:21

the above versions would have the fix but you might be using deps.edn or project.clj to manage your dependencies so you'd need to upgrade shadow-cljs there

haywood17:03:00

oof why do I have shadow in my deps.edn AND package.json

haywood17:03:25

well, that fixed it, was only upgrading the version in the package.json…

Azzurite17:03:40

whenever I get some kind of runtime error during reload while developing, there's a small error dialog fixed at the bottom of the page. This does not disappear until I completely reload the page. Is that a bug or supposed to be like that?

thheller17:03:33

define runtime error?

Azzurite17:03:13

I fix that, and the page reloads again and everything is fine, except that the error stays at the bottom

thheller17:03:00

ok that looks like you are running code directly on load? (eg. directly calling (render)) in your file? you should not be doing that.

Azzurite17:03:42

well yeah, when I load the page the js should execute, should it not?

thheller17:03:24

no, you should be using the lifecycle hooks provided for that https://shadow-cljs.github.io/docs/UsersGuide.html#_hot_code_reload

Azzurite17:03:00

oh thanks so basically use one namespace on the production site that immediately executes and another with the lifecycle hooks while developing?

thheller17:03:16

no, use :init-fn in your module to call the code you want to run on startup

Azzurite17:03:32

ok well I'll read some more

thheller17:03:49

as the blogpost explains

thheller17:03:15

the pattern of swapping out namespaces in production is bad and absolutely advised against

Azzurite17:03:48

yeah I only read the user guide and maybe I didn't understand that perfectly

Azzurite17:03:08

it seemed more like "you can do that if you want" not "you need to do that actually"

thheller17:03:37

well the issue with running code directly on load is that it interrupts that reload cycle

thheller17:03:53

shadow-cljs cannot know WHAT failed during load, it only knows that something failed and abort

thheller17:03:59

leaving your code in an undefined state

Azzurite17:03:13

makes a lot of sense, just didn't get that by myself 😄

thheller17:03:16

thats why the error dialog doesn't go away

Azzurite17:03:57

so much shit to learn when you're teaching yourself

Azzurite17:03:24

really appreciate the help & quick reply ❤️

thheller17:03:50

yeah thats why shadow-cljs tries to keep everything as minimal as possible. unfortunately some older blogposts, tutorials, templates use more complex setups making things more complicated than they need to be. IMHO, YMMV 😛

Azzurite18:03:22

yeah I'm not an inexperienced dev, only in clj/cljs... I so so love getting everything as simple as possible, which is basically what I've been doing so far. And shadow-cljs is a really nice piece of software in the simplicity area

👌 1
raspasov06:03:08

@UCULU82G3 “as simple as possible” sounds like you’re on the good path 🙂

Azzurite12:03:30

@U050KSS8M yeah over-engineering is very rampant where I'm from, took a bit to get to this path not easy when you're doing it alone and "only" trying to scour the interwebs for the "right things to do" - so much knowledge in people's heads but not written down I feel 😄

raspasov16:03:34

@UCULU82G3 “over-engineering” - what language/framework?

Azzurite19:03:32

@U050KSS8M I more meant geographically/where I've been working/studying so far, Germany but language is Java/C#/JS mostly

raspasov20:03:09

👍 understood :)

andersmurphy22:03:44

Does anyone know of a good example of using a service worker with shadow-cljs?

andersmurphy22:03:52

(in terms of shadow-cljs.edn set up)

thheller08:03:29

{:target :browser :modules {:sw {:init-fn my.sw/init :web-worker true}}} should be ok

thheller09:03:48

FWIW I think its better to use a dedicated tool for this like https://developers.google.com/web/tools/workbox