Fork me on GitHub
#shadow-cljs
<
2023-04-11
>
defa07:04:14

Hello everyone! I tried to set up a new project with shadlow-cljs and react-native but get an error when launching the app on Android (iOS not tested): Property 'setTimeout' doesn't exist Also when trying to connect via nrepl I get No available JS runtime. Obviously there is something not set up correctly.

thheller07:04:44

what is your build config?

defa07:04:04

;; shadow-cljs configuration
{:deps         {:aliases [:app]}

 :dependencies []

 :builds       {:app {:target :react-native
                      :init-fn          
                      :output-dir       "react-native/app"
                      ;:asset-path       "images"
                      :compiler-options {:infer-externs :auto
                                         :output-feature-set :es5}
                      :js-options       {:js-package-dirs ["react-native/node_modules"]}
                      :devtools         {:preloads [shadow.remote.runtime.cljs.browser]}

                      }}
 :nrepl {:port 9876}
 }

defa07:04:37

I used a similar setup in the past..

thheller07:04:49

looks fine so far. where does it want to use setTimeout?

defa07:04:03

shadow-cljs 2.22.9

thheller07:04:17

no clue if thats even supposed to be available in RN. they changed the default engine to hermes not too long ago. dunno if thats available there

defa07:04:22

ReferenceError: Property 'set Timeout' doesn't exist
at global ()
at eval (native
at anonymous (: 8081/index.bundle? platform=android&dev=true&minify=false&app=com

defa07:04:43

Okay, so I'll try to find the switch to turn off hermes...

defa07:04:12

In gradle.properties I set hermesEnabled=false and now I get: Can't find variable: setTimeout

thheller07:04:21

yeah sorry, no clue. I don't have a working react native setup so I can't test myself

thheller07:04:27

I'm not sure if its supposed to be available or not

thheller07:04:42

which RN version? maybe ask in #C0E1SN0NM

defa07:04:57

Can't find variable: setTimeout
Can't find variable: setTimeout
eval code eval@ native code]

false&runModule=true:1601:14

false&runModule=true:2662:22

defa07:04:24

Thanks, Thomas. I'll ask there. Seems not to be a problem with shadow-cljs.

defa07:04:34

"dependencies": {
    "react": "18.2.0",
    "react-native": "0.71.6"
  },

defa11:04:09

@thheller the error was caused by not having react-native imported due to incomplete code or premature compilation 🙈 Sorry. Works with Hermes and the latests deps.

👍 2
oliver12:04:40

Hi everyone, I'm choosing this channel for my question, as there seems to not be one dedicated to clojure cli/deps.edn yet and it is about integrating it with shadow-cljs. I use CIDER for Clojurescript coding. Until now, I used to run shadow-cljs directly, outside of Emacs, then connecting to it. To inject the correct middleware I have the following in my global ~/.shadow-cljs/config.edn:

{:dependencies
 [[cider/cider-nrepl "0.28.5"]
  [refactor-nrepl/refactor-nrepl "3.6.0"]
  [cider/piggieback "0.5.2"]]}
I have now tweaked a project to use deps.edn in conjuction with shadow-cljs, which I now start with clj -M:shadow-cljs watch server. The corresponding alias definition in the project-local deps.edn looks as follows:
{:shadow-cljs {:extra-deps {thheller/shadow-cljs {:mvn/version "2.18.0"}
                                      cider/cider-nrepl {:mvn/version "0.28.5"}
                                      refactor-nrepl/refactor-nrepl {:mvn/version "3.6.0"}
                                      cider/piggieback {:mvn/version "0.5.2"}}
                         :main-opts   ["-m" "shadow.cljs.devtools.cli"]}}
This works fine, but I would very much prefer to pin the middleware versions globally, since they are needed by my editor, not by the project per se: After all, other team members might be using different versions of CIDER and the respective middleware. I know I could make the entire alias available globally by moving it to ~/.clojure/deps.edn, but that would include the version of shadow-cljs as well. That version, however, is project-specific, so it should be specified locally inside the project. The same would also apply for dev-only dependencies like Re-frame-10x etc. The way vanilla shadow-cljs merges configurations was sufficiently fine-grained to allow for dev-only-dependencies coming from local and global configs at the same time. This seems to not be the case with deps.edn. E.g. it doesn't work to have the following in ~/.clojure/deps.edn:
{:aliases {:shadow-cljs {:extra-deps {cider/cider-nrepl {:mvn/version "0.28.5"}
                                      refactor-nrepl/refactor-nrepl {:mvn/version "3.6.0"}
                                      cider/piggieback {:mvn/version "0.5.2"}}}
           }}
and reduce the alias in my project's deps.edn to
:aliases {:shadow-cljs {:extra-deps {thheller/shadow-cljs {:mvn/version "2.18.0"}}
                         :main-opts   ["-m" "shadow.cljs.devtools.cli"]}}
Apparently, these aliases are not merged and there is no CIDER middleware in the nrepl started. Is there any recipe to achieve the merging of :extra-deps from global and local deps.edn files? Many thanks for any insights you may give me!

thheller12:04:25

just give it a different name and activate both?

thheller12:04:40

clj -M:cider:shadow-cljs server or whatever

oliver12:04:06

That works? I'll try at once…

oliver13:04:32

@thheller That does indeed work, Thanks a lot. I wasn't aware of the possibility to activate more than one alias like that… after all, this was my first exposure to deps.edn. Thanks again for taking the time to address this and for making shadow-cljs the joy it is!

Ben Lieberman18:04:37

Am I mistaken that simple optimizations should not mangle names? If I compile with just npx shadow-cljs compile app everything works great but when I use npx shadow-cljs release app with optimizations set to simple I get reference errors in the console

thheller19:04:01

it does rename some things, but not properties on objects. only locals and stuff usually which shjouldn't break things

Ben Lieberman19:04:13

Is there gonna be a notable difference between using compile and release if I'm just compiling a single small module? I'm guessing not and will probably leave it.

thheller23:04:00

compile is a dev build with no optimizations applied. release should be used, but implies optimizations which is slower to build but also substantially smaller in filesize