clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
Felipe 2021-06-03T10:27:10.485400Z

why does clj -M -m cljs.main -co build.edn -v -c -r followed by cljs.user=> (require 'react) work but trying to do the same with a browser REPL launched from

(require '[cljs.repl :as repl])
(require '[cljs.repl.browser :as browser])  ;; require the browser implementation of IJavaScriptEnv
(def env (browser/repl-env)) ;; create a new environment
(repl/repl env)
doesn't? in this case, I get
cljs.user=> internal/modules/cjs/loader.js:796
    throw err;
    ^

Error: Cannot find module '@cljs-oss/module-deps'
Require stack:
- /home/felipecortez/Dev/hello-bundler/[eval]
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:793:17)
    at Function.Module._load (internal/modules/cjs/loader.js:686:27)
    at Module.require (internal/modules/cjs/loader.js:848:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at [eval]:8:13
    at Script.runInThisContext (vm.js:116:20)
    at Object.runInThisContext (vm.js:306:38)
    at Object.<anonymous> ([eval]-wrapper:9:26)
    at Module._compile (internal/modules/cjs/loader.js:955:30)
    at evalScript (internal/process/execution.js:80:25) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/home/felipecortez/Dev/hello-bundler/[eval]' ]
}

Execution error (InternalError) at (<cljs repl>:1).
too much recursion

cljs.user=> Execution error (TypeError) at (<cljs repl>:1).
cljs.user.node$module$react is undefined
I'm following https://clojurescript.org/guides/webpack and https://clojurescript.org/guides/quick-start

p-himik 2021-06-03T11:48:50.485700Z

> too much recursion This particular thing was popping up for someone else when they were reusing the same browser page without refreshing it, IIRC.

Siddharth yadav 2021-06-03T12:01:24.487200Z

How do I get and set a vector in local storage? Googled but could not find a satisfactory answer.

Felipe 2021-06-03T12:07:44.487300Z

I think that's because the compiled file had a repl/connect line. if I remove it, that error is gone but I still get the MODULE_NOT_FOUND error

Felipe 2021-06-03T12:11:00.487500Z

following https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage :

(. js/window.localStorage setItem "myCat" "Tom")
(. js/window.localStorage getItem "myCat")

(. js/window.localStorage setItem "myCats" #js ["Tom" "Tim"])
(. js/window.localStorage getItem "myCats")
seems to work!

Felipe 2021-06-03T12:11:42.487900Z

you do get a comma-separated string, though

Felipe 2021-06-03T12:11:54.488100Z

(. js/window.localStorage getItem "myCats")
;; => "Tom,Tim"

borkdude 2021-06-03T12:15:42.488300Z

you could also just store some EDN-as-string in there

👍 1
Felipe 2021-06-03T12:15:44.488500Z

but then you could run stringify / parse for serialization/deserialization (js/JSON.stringify #js ["Tom"])

dnolen 2021-06-03T12:55:39.489200Z

@felipecortezfi the commands are not the same

dnolen 2021-06-03T12:55:56.489600Z

in the CLI case you are passing build.edn in the scripted case you are not

dnolen 2021-06-03T12:56:47.490400Z

because the build defines :main all node_modules can be resolved - but in the latter case there's nothing to analyze so they won't be

Felipe 2021-06-03T12:58:13.491400Z

makes sense! so should I be passing some argument to repl-env when starting the REPL? or something else

dnolen 2021-06-03T13:36:30.491900Z

the compiler options

dnolen 2021-06-03T13:38:04.492800Z

the pattern is generic, the details about Krell and nREPL here are uninteresting

Felipe 2021-06-03T13:41:58.493200Z

(cljs.repl/repl env :main 'hello-bundler.core :target :bundle)
seems to work! thanks!

Felipe 2021-06-03T14:03:05.495Z

what does :main have to do with node_modules , though?

dnolen 2021-06-03T14:04:50.496100Z

you have to look at :main to know the dependency graph, you also need more than :main you might have foreign libs

dnolen 2021-06-03T14:05:26.496900Z

these might mask things found in node_modules there's no way to know w/o looking at :main , comparing foreign libs and what's in node_modules in order to figure out what you are actually requiring

Felipe 2021-06-03T14:08:56.498Z

got it. so even if my main file is just a (ns hello-bundler) , passing that to the compiler (interpreter?) lets it build the dependency graph, which includes node_modules + cljs libs?

dnolen 2021-06-03T14:10:19.498500Z

a simple rule - you always have to pass :main

dnolen 2021-06-03T14:10:25.498700Z

unless you're just messing around w/ a REPL

Felipe 2021-06-03T14:12:03.498900Z

got it!

dnolen 2021-06-03T14:15:27.499500Z

also note if you want to avoid a lot of confusion - you really should pass all of build.edn to the REPL script

dnolen 2021-06-03T14:15:40.499900Z

if there's any difference you will be very surprised later

Felipe 2021-06-03T14:19:25.001Z

yep, I guessed so. that cider piggieback snippet you linked is pretty useful! thanks!

danielneal 2021-06-03T15:46:50.004200Z

I'm developing a cljs library to be used from js. The cljs code seems to work fine with optimizations: none via figwheel, but when I build a js file with :optimizations :simple for use in the js front end I get this error.

TypeError: right-hand side of 'in' should be an object, got undefined
java.time.global$module$_CIRCA_js_joda$core = goog.global.JSJoda;
java.time.Period = goog.object.get(java.time.global$module$_CIRCA_js_joda$core, "Period");
so I'm guessing it's something to do with the cljc.java-time dependency, which AFAIK uses cljsjs to package the js-joda dep, but I don't know where to go from here in the debugging process. Any ideas?

thheller 2021-06-03T15:53:06.005200Z

looks like JSJoda is just undefined? I think goog.object.get uses in

danielneal 2021-06-03T16:11:28.006100Z

yep I think you're right. I think it might be because the lib provides js-joda via cljsjs and I need to provide it by some other route

danielneal 2021-06-03T16:51:58.006800Z

tried supplying it through npm/figwheel.main but no joy. Maybe it's time to switch this project over to shadow 🙂

😎 1
dnolen 2021-06-03T17:06:07.008100Z

@danieleneal you can check goog.global.JSJoda easily yourself

dnolen 2021-06-03T17:06:24.008500Z

either it's there or it isn't, if it's not there then you know what to look more closely at

danielneal 2021-06-03T17:17:58.008700Z

good point 🙂

beders 2021-06-03T17:23:31.009900Z

is anyone aware of a Chrome devtools extension that makes it easier to display application/transit+json content?

dnolen 2021-06-03T18:42:06.010500Z

I started one years ago but never got finishing - don't have the code anymore - but it really should be easy to do

borkdude 2021-06-03T18:47:15.011400Z

what I sometimes do is just copy paste the thing into a file and then pipe it to jet (https://github.com/borkdude/jet) but https://djblue.github.io/portal/ has a transit viewer as well, so you could just copy paste it in there as well. obviously not as convenient as a devtools extension that does it directly

1
beders 2021-06-03T19:05:25.013Z

yup, I currently have a Automator script that does exactly this.

beders 2021-06-03T19:07:21.013700Z

i.e. takes the clipboard content, runs it through jet and puts it back into the clipboard as EDN