Fork me on GitHub
#shadow-cljs
<
2022-10-08
>
pez15:10:55

What could I be doing wrong?

(require '[goog.object :as gobj]) => nil
gobj => Use of undeclared Var calva.read-config/gobj
Putting the require in a :require in the ns form gives the same result. I can use goog.object this way: (js/goog.object.set o k v), but I would prefer to use :require...

thheller17:10:20

@pez gobj is just a namespace binding? so you'd use gobj/get?

pez18:10:33

Yes, that's how I tried to use it, but got Cannot read properties of undefined (reading 'set').

thheller18:10:00

dunno the full context, so can't say much. (:require [goog.object :as gobj]) and (gobj/set x "thing" 1) definitely works

thheller18:10:38

but goog.object is one of those new goog.module. so there are caveats to using it now. for example in code generated by macros

pez18:10:25

The longer story is that I wanted to make my own version of cljs.core/clj->js, so I copied it https://github.com/clojure/clojurescript/blob/master/src/main/cljs/cljs/core.cljs#L11031-L11056 and also copied how goog.obj was required. Then when trying my local version of clj->js, I got that ^ error.

thheller18:10:25

you can just use unchecked-get and unchecked-set from cljs.core instead. works the same

thheller18:10:59

that is definitely fine to use

pez18:10:52

unchecked-set works great. Thanks!

pez18:10:30

I'm still confused about why what I did didn't work, though.

thheller19:10:49

I don't know what you did so no clue either 😛

thheller19:10:20

I'm using it frequently in plenty of places, so I'm sure it works

pez19:10:29

What I did: 1. Copied clj->js from core.cljs and pasted it in my file as my-clj->js. 2. Copied [goog.object :as gobject] from the ns form of core.cljs and pasted it in my ns from. 3. Evaluated (my-clj->js {:foo 1}) => BOOM Cannot read properties of undefined (reading 'set').

thheller19:10:02

yeah but evaluation order and build order and stuff matters here

thheller19:10:27

so the REPL just might have been in a weird state

pez19:10:57

I actually tried to restart the REPL. Let me try that again...

pez19:10:17

Same with a fresh REPL...

thheller19:10:38

hmm indeed. I can reproduce in the REPL, just not in a regular build

pez19:10:42

I like unchecked-set so I am fine. And I'm not confused any longer. 😃 Even if it would have been better that I had done something weird rather than there being this REPL mystery.

thheller19:10:25

I started using unchecked-set in my own code. no longer worth the trouble with goog.object since the weird goog.module changes

pez19:10:28

Ah, so you have already figured out what causes it. Nice mini-repro!

(gobj/set #js {} "x" 1)
I get a bit surprised that it evaluates to 1. Never thought about the return value of these before. I notice that also:
(set! (.-x #js {}) "y") => "y"

thheller19:10:25

thats just how JS works foo["x"] = 1; returns 1

pez19:10:34

Thanks! Didn't know that either. Very good to know.

thheller17:10:39

using the :as as a variable only works for npm JS requires, not for CLJS or closure namespaces

peterdee18:10:46

Can an error configuring logging cause shadow to not provide a JS runtime. I get ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...

thheller18:10:25

no, this is unrelated. usually caused by you having additional logging related dependency on the classpath

thheller18:10:10

(or setting up logging incorrectly in some way). if you start shadow-cljs embedded it'll inherit the JVM logging you configured

oskarkv19:10:16

Don't know if this is Shadow-CLJS's fault, but I'm getting this error when trying to use garden.

app.css> (g/css)

Execution error (ReferenceError) at (<cljs repl>:1).
Can't find variable: garden
:repl/exception!
I'm using deps.edn where I have added garden, and my ns declaration looks like this:
(ns app.css
  (:require
   [garden.core :as g]
   [garden.stylesheet :as gs]
   [re-frame.core :as rf]))
I don't get any error when using re-frame, only with garden. Any ideas of what's wrong?

thheller19:10:12

not enough context to comment. how did you require things? were there any warnings? errors during load?

thheller19:10:39

I've never used garden, so no clue what it does on load. might be doing something in macros. no clue.

oskarkv19:10:35

There was one warning:

------ WARNING - :redef --------------------------------------------------------
 Resource: <eval>:390:1
 abs already refers to: cljs.core/abs being replaced by: garden.color/abs
--------------------------------------------------------------------------------
As for how I required things, I required it with the ns macro, as I showed.

thheller19:10:37

well by default the REPL doesn't load any code when there are warnings

thheller19:10:44

so that would prevent it from loading anything

oskarkv19:10:31

Is there a workaround? Or can't I use garden just because it had a warning?

thheller19:10:35

you can set :devtools {:ignore-warnings true} in the build config

oskarkv19:10:39

OK, thanks!

thheller19:10:48

I think you can update garden? I believe this has been fixed

oskarkv19:10:30

This looked like the latest version, according to Clojars and github.

thheller19:10:25

looks fixed. maybe there was no release after that? dunno

oskarkv19:10:33

Thanks again!