Fork me on GitHub
#shadow-cljs
<
2022-08-03
>
Alex Warren06:08:08

hi hi, I am looking for a little help, I have a build with :target :node-library and I want to use js/performance.now which is a browser global, available with const { performance } = require('perf_hooks'); on node. see this https://stackoverflow.com/questions/23003252/window-performance-now-equivalent-in-nodejs ... Is there an easy way to get this work, I am hacking with someone elses code, so I am mostly in the dark with clojure tbh. I tried (:require ["perf_hooks" :refer (performance)] ) but that was giving me "Use of undeclared Var performance/now" I am stuck :|

thheller07:08:55

@exrhizo with :refer you'd do (.now performance), :refer does not set up a namespace alias so performance/ doesn't work. you can do (:require ["perf_hooks$performance" :as perf]) and then (perf/now).

🙌 1
zakkor14:08:41

When I eval something in the REPL, I get an error that looks like this:

:repl/exception!
; 
; Execution error (TypeError) at (<cljs repl>:1).
Cannot read properties of null (reading 'cljs$core$IFn$_invoke$arity$1')
I can't figure out what's going wrong using just this info, is there any way to get more detailed traces?

thheller15:08:39

this usually means you are doing something like (foo 1 2 3) when foo is nil

zakkor15:08:34

yeah, but is there any way of figuring out which "foo" it is? 😄

thheller16:08:56

well you are calling the code?

zakkor16:08:36

(defn calls-nil [f] (f 1 2 3 4 5))
(calls-nil nil)
Eval in REPL using standard Calva shortcut gets me:
:repl/exception!
; 
; Execution error (TypeError) at (<cljs repl>:1).
Cannot read properties of null (reading 'call')

thheller16:08:17

well that is sort of an artifact of how the code is generated differently when eval'd in the REPL.

thheller16:08:23

it is the basically same error though

thheller16:08:59

if this is in Calva it might also be dropping some additional information

thheller16:08:05

emacs also seems to be doing that

thheller16:08:46

(not on this example, but make sure to look at the server log in case there is any)

zakkor16:08:27

if, for example, I set the :init-fn to calls-nil, I get proper traces in the browser console:

zakkor16:08:57

but if I eval from Calva, nothing gets printed to the browser console

zakkor16:08:09

nothing in the shadow-cljs terminal log either :thinking_face:

thheller16:08:16

well you can get that via (.-stack *e) after the errors

thheller16:08:15

(js/console.log *e) would give you the above too I guess

zakkor16:08:51

nice, thanks! the second one is great, the first one isn't sourcemapped

thheller16:08:11

yeah source mapping is the problem. didn't write that yet for the errors

zakkor16:08:26

is this something that could be fixed on Calva's side?

zakkor16:08:42

@thheller hmm, any other way of getting the sourcemapped trace from *e , or is it only possible by js/console.log ing it?

zakkor16:08:04

would have been cool to be able to see/click the sourcemapped error without needing to switch to the browser window

thheller16:08:58

well you can implement it 😉

thheller16:08:16

in case of console.log the browser does it for us

thheller16:08:29

I haven't found a way to make it do that in userland code

zakkor16:08:01

I'll give it a shot and report findings if I manage to do anything 😄 Thanks for shadow-cljs by the way, it's a great project

thheller16:08:18

thats where the string for the error is generated

thheller16:08:13

by all means feel free to change either place and make it better 😉

zakkor16:08:29

awesome, thanks!