shadow-cljs

https://github.com/thheller/shadow-cljs | https://github.com/sponsors/thheller | https://www.patreon.com/thheller
thheller 2021-02-02T09:26:45.300600Z

@rameezkhan.sa saw your question on twitter. did you sort it out?

Rameez 2021-02-02T09:29:22.301600Z

Nope not yet. :)

Rameez 2021-02-02T09:29:32.302Z

Let me get some more details...

Rameez 2021-02-02T09:31:43.302200Z

I'm behind a corporate HTTP proxy currently, if I specify proxy details as follows in my projects local shadow-cljs.edn it works fine:

thheller 2021-02-02T09:31:46.302400Z

I assume by proxy you meant the :proxy in shadow-cljs.edn for dependency resoltiuon?

Rameez 2021-02-02T09:31:55.302600Z

{:source-paths
 ["src"]

 :proxy {:host "127.0.0.1" :port 3128}
 :nrepl {:port 9000}

 :dependencies
 [[cider/cider-nrepl "0.25.8"]
  [reagent "1.0.0"]
  [re-frame "1.1.2"]]

 :builds {:app {:target     :browser
                :output-dir "public/js"
                :modules    {:main {:entries [<http://timer.app|timer.app>]}}
                :devtools   {:http-root "public"
                             :http-port 3000}}

          :prod {:target     :browser
                 :output-dir "public/js"
                 :modules    {:main {:entries [<http://timer.app|timer.app>]}}
                 :release    {:compiler-options {:optimizations :simple}}}}}

thheller 2021-02-02T09:32:07.302800Z

yeah that should be :maven {:proxy ...}

Rameez 2021-02-02T09:32:09.303Z

Correct.

Rameez 2021-02-02T09:32:14.303200Z

ah!

Rameez 2021-02-02T09:32:17.303400Z

cool!

thheller 2021-02-02T09:32:19.303600Z

that'll then work in the other config too

Rameez 2021-02-02T09:32:26.303800Z

nice! 🙂

Rameez 2021-02-02T09:32:30.304Z

Thanks for the help!

thheller 2021-02-02T09:32:56.304200Z

btw the :prod build is an anti-pattern in shadow-cljs

thheller 2021-02-02T09:33:10.304400Z

just put the :release bit into the :app config

thheller 2021-02-02T09:33:53.304600Z

optimizations are only applied to release builds so it does not affect the watch or compile builds

Rameez 2021-02-02T09:34:05.304800Z

Ah got you! Thanks for the spot.

Rameez 2021-02-02T09:34:19.305Z

Learnt something new 🙂

thheller 2021-02-02T09:35:31.305200Z

yeah common mistake people make that have used other tools before (or read other docs) 🙂

👍 1
Rameez 2021-02-02T09:41:31.305600Z

Would you then just do shadow-cljs release app ?

thheller 2021-02-02T09:41:45.305800Z

yes

Rameez 2021-02-02T09:41:49.306Z

Cool

Rameez 2021-02-02T09:47:13.306200Z

The proxy still doesn't seem to work globally set.

Rameez 2021-02-02T09:47:18.306400Z

This is what I have set:

Rameez 2021-02-02T09:47:30.306600Z

{:mvn {:proxy {:host "127.0.0.1" :port 3128}}}

Rameez 2021-02-02T09:47:52.306800Z

file-path is: /home/rameezk/.shadow-cljs/config.edn

thheller 2021-02-02T09:47:55.307Z

:maven not :mvn

Rameez 2021-02-02T09:47:57.307200Z

That look right?

Rameez 2021-02-02T09:48:00.307400Z

ah cool

Rameez 2021-02-02T09:48:29.307600Z

Apologies, that works 🙂

👍 1
Aron 2021-02-02T16:10:22.311300Z

please give me a hint with regards to missing source maps e.g. DevTools failed to load SourceMap: Could not parse content for <http://localhost:7000/cljs-runtime/goog.events.events.js.map>: Unexpected token &lt; in JSON at position 0 the < part is because the static server returns the index.html, but the file is missing too. I am not even sure if the file should or shouldn't exist and I don't need the source maps right now at all, but I suspect I am doing something wrong again and that's why I have these warnings

thheller 2021-02-02T16:15:19.311800Z

my guess is you have :asset-path "/" but the files aren't actually located there. it should match the path you use to serve the JS. so maybe /js or so

Aron 2021-02-02T16:17:46.312400Z

that was it, thank you

Aron 2021-02-02T16:18:34.313400Z

funny thing is, i did check the files by name before and i saw some source map files, but not exactly the one i was checking and i concluded it must be something else, not just a path issue

hadils 2021-02-02T16:42:49.314600Z

Hi. I am having problems with hot reload. I ran shadow-cljs watch app --verbose and found that it was using a different IP address than expo. How can I get them to be the same?

hadils 2021-02-02T17:01:24.315Z

Thank you @thheller!

thheller 2021-02-02T17:10:23.315500Z

I still need a better place to configure this somehow 😛

jaime 2021-02-02T23:13:08.318800Z

Hi, I'm trying to run cljs-test in repl in my react-native project. But I'm getting this error when the app loads in the emulator EDIT: error has changed

[Wed Feb 03 2021 03:48:56.126]  WARN     The shadow-cljs Websocket was disconnected.
[Wed Feb 03 2021 03:48:56.127]  ERROR    shadow-cljs - remote-error {"isTrusted": false, "message": "failed to connect to /10.212.134.22 (port 9630) from /10.0.2.16 (port 36722) after 10000ms"}
Now when I send forms to repl, I got this error
No available JS runtime.
See <https://shadow-cljs.github.io/docs/UsersGuide.html#repl-troubleshooting>

dima 2021-02-03T13:52:42.322Z

I’m adding `{:closure-defines {"shadow.cljs.devtools.client.env.server_host" "%IP-ADDRESS%"}}` to `(shadow/watch options)` to set correct IP address

thheller 2021-02-03T15:43:22.322300Z

what the heck does this do? is this some kind of trick I don't know about? what is %IP-ADDRESS%? or do you just set the actual IP there?

jaime 2021-02-03T20:56:32.335400Z

Hi @trybeee, how can I get the IP address? Is it the IP of the emulator? I don't know how to get the IP

dima 2021-02-04T09:03:31.371900Z

%IP-ADDRESS% is a placeholder for your machine real ip

dima 2021-02-04T09:05:06.372100Z

{:closure-defines {"shadow.cljs.devtools.client.env.server_host" "192.168.1.111"} for instance

dima 2021-02-04T09:05:43.372300Z

@thheller server_host is used here https://github.com/thheller/shadow-cljs/blob/3e559b8f9ea80cc1ad1c51772fe4aa8c099a1159/src/main/shadow/cljs/devtools/client/env.cljs#L84 if not set, it uses “localhost” which doesn’t work in iOS simulator (it needs ip address to connect)

dima 2021-02-04T09:10:16.372700Z

@jaime.sangcap It needs to be IP address of your host machine (where shadow-cljs is running), on mac you can get it with ipconfig getifaddr en0 where en0 is your network interface

thheller 2021-02-04T09:49:45.372900Z

@trybeee well for react-native there is :local-ip "1.2.3.4" in your build config or via config merge. going through closure-defines is kinda backwards. just thought there was some magic %IP-ADDRESS% placeholder or something that metro will replace but I guess not.

dima 2021-02-04T11:08:33.373100Z

Thanks @thheller Nice to know there is local-ip option. At the time i was adding hack with server-port override, it wasn’t there i think.

thheller 2021-02-04T11:11:28.373300Z

that has always been there, just not documented. I don't do react-native myself so the entire section of the code and docs is lacking a lot of clarity 😞

jaime 2021-02-05T16:41:41.444200Z

@trybeee thanks! I will try that one. The whole time I'm thinking shadow and emulator are running in localhost. I want to dig more into the architecture, do you have recommended resources that I can read?

jaime 2021-02-05T17:34:48.448300Z

Thanks! it works now by specifying the LAN IP. If I understand correctly now, my laptop running the shadow-cljs and emulator will be two device connected to the LAN. When shadow-cljs runs in localhost, the websocket client running in the emulator tries to connect to localhost which is then the emulator not my laptop? Where the solution to put the specific IP will make the websocket client point to my laptop LAN IP which is where the websocket server is running right?

dima 2021-02-05T17:38:38.448700Z

Yes, client running in the emulator needs IP to connect to server which is running on your laptop

thheller 2021-02-05T17:45:50.448900Z

technically it doesn't use localhost by default for react-native. it uses the IP it gets from your system. specifically this part of the code

thheller 2021-02-05T17:46:28.449400Z

but if your machine has multiple IPs it sometimes picks the incorrect one. still need to tune that mechanism a little I guess.

thheller 2021-02-05T17:47:00.449600Z

but yes, your emulator has a different IP and connects over the "network" not localhost

jaime 2021-02-05T18:11:46.449800Z

Thanks @thheller @trybeee for these pointers. I learned something new again

jaime 2021-02-02T23:16:27.319100Z