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> too much recursion This particular thing was popping up for someone else when they were reusing the same browser page without refreshing it, IIRC.
How do I get and set a vector in local storage? Googled but could not find a satisfactory answer.
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
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!you do get a comma-separated string, though
(. js/window.localStorage getItem "myCats")
;; => "Tom,Tim"
you could also just store some EDN-as-string in there
but then you could run stringify / parse for serialization/deserialization
(js/JSON.stringify #js ["Tom"])
@felipecortezfi the commands are not the same
in the CLI case you are passing build.edn
in the scripted case you are not
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
makes sense! so should I be passing some argument to repl-env when starting the REPL? or something else
the compiler options
https://github.com/vouch-opensource/krell/wiki/Tooling-Integration---Emacs%2C-Cursive%2C-VSCode-etc.
the pattern is generic, the details about Krell and nREPL here are uninteresting
(cljs.repl/repl env :main 'hello-bundler.core :target :bundle)
seems to work! thanks!what does :main
have to do with node_modules
, though?
you have to look at :main
to know the dependency graph, you also need more than :main
you might have foreign libs
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
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?
a simple rule - you always have to pass :main
unless you're just messing around w/ a REPL
got it!
also note if you want to avoid a lot of confusion - you really should pass all of build.edn
to the REPL script
if there's any difference you will be very surprised later
yep, I guessed so. that cider piggieback snippet you linked is pretty useful! thanks!
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?looks like JSJoda
is just undefined
? I think goog.object.get
uses in
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
tried supplying it through npm/figwheel.main but no joy. Maybe it's time to switch this project over to shadow 🙂
@danieleneal you can check goog.global.JSJoda
easily yourself
either it's there or it isn't, if it's not there then you know what to look more closely at
good point 🙂
is anyone aware of a Chrome devtools extension that makes it easier to display application/transit+json
content?
I started one years ago but never got finishing - don't have the code anymore - but it really should be easy to do
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
yup, I currently have a Automator script that does exactly this.
i.e. takes the clipboard content, runs it through jet
and puts it back into the clipboard as EDN