Fork me on GitHub
#clojurescript
<
2021-06-03
>
Felipe10:06:10

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-himik11:06:50

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

Felipe12:06:44

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

Siddharth yadav12:06:24

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

Felipe12:06:00

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!

Felipe12:06:42

you do get a comma-separated string, though

Felipe12:06:54

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

borkdude12:06:42

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

👍 3
Felipe12:06:44

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

dnolen12:06:39

@felipecortezfi the commands are not the same

dnolen12:06:56

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

dnolen12:06:47

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

Felipe12:06:13

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

dnolen13:06:30

the compiler options

dnolen13:06:04

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

Felipe13:06:58

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

Felipe14:06:05

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

dnolen14:06:50

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

dnolen14:06:26

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

Felipe14:06:56

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?

dnolen14:06:19

a simple rule - you always have to pass :main

dnolen14:06:25

unless you're just messing around w/ a REPL

dnolen14:06:27

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

dnolen14:06:40

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

Felipe14:06:25

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

danielneal15:06:50

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?

thheller15:06:06

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

danielneal16:06:28

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

danielneal16:06:58

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

😎 3
dnolen17:06:07

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

dnolen17:06:24

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

danielneal17:06:58

good point 🙂

beders17:06:31

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

dnolen18:06:06

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

borkdude18:06:15

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

portal 3
beders19:06:25

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

beders19:06:21

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