This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-04-26
Channels
- # announcements (10)
- # aws (5)
- # babashka (27)
- # beginners (175)
- # boot (1)
- # braveandtrue (2)
- # calva (11)
- # cider (13)
- # clj-kondo (91)
- # cljs-dev (54)
- # cljsrn (20)
- # clojure (164)
- # clojure-gamedev (3)
- # clojure-uk (43)
- # clojurescript (185)
- # core-async (6)
- # core-typed (1)
- # cursive (1)
- # docker (2)
- # emacs (2)
- # figwheel-main (78)
- # fulcro (69)
- # off-topic (20)
- # pathom (30)
- # planck (3)
- # re-frame (6)
- # reagent (70)
- # reitit (26)
- # ring (1)
- # shadow-cljs (120)
- # tools-deps (6)
- # vim (9)
Anyone using shadow-cljs
developing chrome extension with background script
. I have a few issues which I don't really understand.
1. when I didn't use background script things seemed to be no issue
2. when I started using background I had issue with manifest.json / content-security-policy something to do with unsafe code / eval
3. also with background script in vscode with Calva
when trying to connect to repl, I constantly getting unsafe eval error when trying to execute anything inside the repl
4. one last thing about using Calva
repl in vscode is that there are many "repls" to connect to, background script / content script / etc, sometimes I don't know which repl I'm connected to, I read on shadow-cljs
issue (the one announced support for chrome extension), seems that vscode (and other tooling) do not support connect to multiple repl in this way
Thanks to any comments/suggestions.
Btw, shadow-cljs
Calva
cljs
are awesome! This is my first sorta real / end to end thing that I'm using shadow/calva/cljs for. Very excited.
I can't seem to get watch to work. I am running clj -m cljs.main -w src -co build.edn -c -r
and it shows as watching, but never rebuilds on change. I'm using the new guide.
@theeternalpulse It doesn't auto-refresh the browser for you
even after a browser refresh it doesn't seem to take
I do notice this in the log
java.lang.AssertionError: Assert failed: :nodejs target with :none optimizations requires a :main entry
@theeternalpulse Please share if you found solution to this problem. I m just starting out with clojurescript and stuck at this issue. thanks
@U9S1URQ4T just found this https://clojure.atlassian.net/browse/CLJS-3238 seems to be a blocker, so it's being looked at.
Seems to be closed as well, look forward to the hotfix
@U9S1URQ4T try org.clojure/clojurescript {:mvn/version "1.10.748"}
thank you @theeternalpulse. It is super helpful. I m loving the clojure community.
my build.edn does contain a :main entry, but I'm using the :bundle target
I just ns'd to hello-bundler.core, required it too just for safe measure, added a new (def a 1)
and saved, reloaded the page, typed a
into the repl and got 1
back. Interestingly, you don't have to reload the page for the local repl to know the vars exist. They just return nils until you reload the page.
this is my build.edn
{:main simple-cljs.core
:output-to "out/index.js"
:output-dir "out"
:target :bundle
:bundle-cmd {:none ["npx" "webpack" "--mode=development"]
:default ["npx" "webpack"]}}
using cljs 1.10.741
pretty much everything other than the watch is from the guide
and the app-name of course
I was just able to make a similar error show up when trying to combine :bundle with :modules
`$ clj -m cljs.main -w src -co build.edn -v -c -r
Execution error (AssertionError) at cljs.closure/check-node-target (closure.clj:2352).
Assert failed: :nodejs target with :none optimizations requires a :main entry
(not (and (= target :nodejs) (= optimizations :none) (not (contains? opts :main))))`
Full report at: ...
@theeternalpulse are you using shadow?
no this is from the recent guide for using webpack
I know there are cljs-watch libraries
Is there a way to specify only the route and not the host in cljs-http? I'm making requests like so:
(http/get ""),
But the host changes in production. And so I have to manually change localhost:3000 to the production url, which is undesirable.
I'm using the Luminus template, in which mat least cljs-ajax works without specifying the host, but trying with cljs-http didn't work.
Is there a way to make it work with cljs-http?one solution is doing (http/get (str (:base-url config) "/some-route"))
and config map contains the correct `base-url`
but How do I separate config based on whether I'm in production or development? My production environment is a docker container running on heroku
This is more instructive: https://www.martinklepsch.org/posts/parameterizing-clojurescript-builds.html
That's fine, but how would shadow know whether it's running in production or development?
Parameters can be different: https://shadow-cljs.github.io/docs/UsersGuide.html#closure-defines
I've never really used shadow but I'd assume you can have different builds for prod and dev
hello, for this code, when I clicked the text, it won't change to an input, how can I fix this? Thanks.
defn click-me
[]
(let [clicked (reagent/atom false)]
(fn []
(if @clicked
[:input {:type "text"
:auto-focus true
:on-blur #(reset! clicked false)}]
[:div {:on-click #(reset! clicked true)}
"Click me."]))))
Are you sure that the build is fine and this code is exactly the one that ends up on the page?
Does the :on-click
handler work? Try to put js/console.log
somewhere in there to check.
Seems like your click-me
component is removed and added back to the DOM when you click on it, thus redefining the clicked
each time.
Morning all. I'm trying to get my head around ClojureScript after playing around with Clojure for a while. I'm specifically interested in node.js (not so much in the browser, just yet), but I'm failing at the very first hurdle: I'm running through the tutorial at https://clojurescript.org/guides/quick-start. When I get to the node.js part and compile my hello-world with --target node (`clj -m cljs.main --target node --output-to main.js -c hello-world.core`) it compiles, but when I try to run it:
/home/eamonn/hello-world/out/goog/dom/dom.js:2499
this.document_ = opt_document || goog.global.document || document;
^
ReferenceError: document is not defined
What simple, stupid thing am I missing?/tmp/throwaway $ cat src/hello.cljs
(ns hello)
(prn "hi")
/tmp/throwaway $ clojure -A:cljs-latest -m cljs.main --target node --output-to main.js -c hello
/tmp/throwaway $ node main.js
"hi"
I'm literally going through the Quick Start. That's all I have in the source.
I've been playing around with Clojure for a while, so I do have a global deps.edn in ~/.clojure, but it doesn't mention cljs or goog, in any way.
It's grown a bit large. Let me do a gist (if I remember how to do that)
Ah, here it is. Again, just copied and pasted from QuickStart. I wasn't even near the point of trying anything extraordinary at this point.
gotcha. just making sure to check the basics since like you said there aren't many pieces involved here
I see I also have a ~/.cljs directory, but there's nothing in it but .aot_cache/1.10.742
Same result.
Bingo! Thank you! I was going to go through the https://clojurescript.org/guides/webpack one too, but that requires the latest. I'll stick with 597 while I play around with node. Should I raise an issue?
Where would I raise it/
:thumbsup:
i've done the webpack one and it works fine if you're interested but for sure stay back for node for now
No worries. Thanks for the quick response!
Hi all, I managed to get a small figwheel-main app to work (with leiningen) locally. Now I'm trying to deploy it on heroku, but I'm getting this when running git push heroku master
:
remote: Compiling jogo-interativo.handler
remote: Compiling jogo-interativo.middleware
remote: Compiling jogo-interativo.server
remote: Syntax error macroexpanding at (jetty.clj:1:1).
remote: Execution error (ClassNotFoundException) at .URLClassLoader/findClass (URLClassLoader.java:382).
remote: org.eclipse.jetty.util.ssl.SslContextFactory$Server
I've put jetty dependencies directly in my project.clj like recommended here https://figwheel.org/docs/jetty_conflicts.html and used :exclusions
following recommendations from lein deps :tree
but to no avail. Anyone an idea why my app would work locally but has this jetty dependency problem on heroku?
Thanks!@dnolen Thanks for clarifying about namespaces as strings and how to invoke them! I will test today
Is there something tricky about writing custom reader handlers for CLJS? I am just testing a basic one which prints the value it receives and returns it as is. Of course, works perfectly fine from CLJ. But from Node, the value gets printed and then it throws. Something gets messed up in the token stream because of that returned value, no matter what value. "Clojurescript Exception" ... "Unexpected token"
How can we convert #inst yyyy-mm-dd
date to be used as value
string of <input type="date" value="yyyy-mm-dd"> dom element
(defn inst->dstring [dinst]
(str (.getFullYear dinst) "-" (cl-format nil "~2,'0d" (inc (.getMonth dinst))) "-" (cl-format nil "~2,'0d" (.getDate dinst))))
Used cljs.pprint/cl-format
to do this
I want to do it in better way.
Hi everyone, another beginner-ish question here. I'm try to take one of my very simple Clojure libraries (this one: https://github.com/eamonnsullivan/github-search, which just does a http/post request to Github's API) and make it so that it does the same thing, but as a node library as well, suitable for require(...)ing from JavaScript or publishing as an npm. Is this even possible? Are there any examples out there that I can study? I keep going around in circles with various guides (shadow-clj, http://clojurescript.org), but haven't found a good one for combining Clojure and ClojureScript with mostly common code. (There are plenty of examples for front-end/back-end things with mostly independent code.)
@eamonn.sullivan I believe datascript publishes an npm library. That could serve as an example.
Perfect, thanks!
Hi, there. I notice that cljs.test reports some weird line numbers when the test fails (sometimes line numbers that does not exist in the original file). Is there any way to get the line number of the assertion that failed? I'm playing with Emacs and cljs.test to get some formatting when running cljs.tests, this would be very helpful. Thanks!
@adam678 it's in fact pretty finicky and very easy to get wrong, I don't have time to look at your particularly issue - we do have tests for this you might want to look at those
@dnolen After way longer than I am willing to admit, I discovered that printing something at compile time like I was doing seems to add a "nil" identifier (ie. the result of println
) in the output code. That's why I was getting those "Unexpected token" errors".
Yes, as simple as removing the println form...
Hi, my google-fu is failing me. I'm looking for a simple http-client for ClojureScript that doesn't require me to get my head around all of clojure.async and go macros and stuff. I have a cli that needs to make one POST request and then massage the response. In Clojure, I just used clj-http.client, but the seemingly equivalent cljs-http.client is forcing me to jump through async. That would be fine if I was just writing a cljs script, but this in in a Clojure/ClojureScript common module (cljc). I just want my response and then get on with my life... (i.e., pass it to some common code). Is there not a simpler http client around?
@eamonn.sullivan I nearly just always use whatever is in the JS environment instead of looking for a wrapper
@alexander.890 there's not one function for that
@dnolen thank you.
As a followup is it common to extend the functionality of goog.object
with clojure protocols to allow it to use get-in | update-in ....
etc.?
you might want to consider https://github.com/mfikes/cljs-bean
if you need to update, then you would have a lot more work todo - but I wouldn't really recommend that anyway
in all my years of doing ClojureScript doing more than cljs-bean
hasn't really seemed very worthwhile
cljs-bean
can "update" objects (it gets a bit funky though). But the gist is that it will CoW the underlying JavaScript object if needed.
Another option is https://github.com/binaryage/cljs-oops
Hello, anyone know of any state viewing tools for clojurescript? Basically I need something like re-frisk, but I need to pass in my own datastructure.
I’m testing the :bundle
target now, getting into some truble with cljsjs dependencies. I’m depending on a lib that’s depending on cljsjs.reactstrap
, the following statement is sent to the browser: cljs.core.load_file("resources/public/js/out/cljsjs/reactstrap/development/reactstrap.inc.js");
. resources/public
is my root for static resources. This fails obviously. My config seems to work for anything but these cljsjs deps
My cljs config
{:main my.main
:output-to "resources/public/js/out/index.js",
:output-dir "resources/public/js/out",
:asset-path "/js/out"
:target :bundle
:bundle-cmd {:none ["npx" "webpack" "--mode=development"]
:default ["npx" "webpack" "--mode=development"]}}
CLJSJS and bundle don't really mix well. you can try the migration strategy I used in shadow-cljs, it should work for this too. see https://shadow-cljs.github.io/docs/UsersGuide.html#cljsjs
there's been some straggling cases, internally :nodejs
target now means we are targeting a Node.js like environment - but no longer that we are actually targeting Node.js - that's covered by a new boolean flag :nodejs-rt
, as people try different combinations of things these cases are coming up
just did a quick audit - and this seems to be close to the last case - if not the last case
@dnolen Ah, great. Ideally I would want to wipe our cljsjs deps, but I think there are some quirks in how libraries use them, so it’s not always easy.
there'll probably be release this coming Friday including all the various things that have come up as people try out the new changes
@dnolen I think it happens sometimes that some lib depends on some other lib being a global in JS. For example I got an error that window.React
could not be found by library code. Currently we solve these cases by inserting globals from our webpack index.js
. What would be the way to do this with bundle target?
you could supply your own index.js
that does the setup as before, and that file requires :output-to
if you need to do that for some reason - then in dev mode you will need to wait for the main ns to load
the :bundle
target is intentionally steps back from these kinds of choices because it's impossible to predict the scenario
@ingesol if you're using deps.edn it would be best to try master (to test) rather than waiting for release
Using lein actually. I’ll see if I can find time to convert project to test last bits
By the way, tested (require ["chart.js" :as chartjs])
and then (chartjs. config)
, compiler complained about missing source for chart.js. I tested that other invocations of that type but with standard naming worked.
(require [some-other-npm])
and (some-other-npm args)
worked. Could be an issue with that specific module, will test some more
Actually, I think I was wrong. Lots of debugging today, so this error was on me. Namespace doing this require compiles without error now.
Hello , i used Clojure in past and autocomplete in cursive was easy i wrote (. ^ClassName myvar ) in clojurescript how to use autocomplete? for example (. js/Document "myid") doesn't work
more generally this is a problem and will probably be addressed in a release in the near future for standard browser API
thank you alot ,i just look a way to set up an ide or text editor for clojurescript with paredit/autocomplete etc second day in clojurescript ,i will ask cursive channel 🙂
so instead of going direct to the browser apis, you could use this stuff for autocomplete
No idea, I just use Cursive myself - Emacs probably not since we dont supply that information yet
we're unlikely to supply it for random Node.js libs since it's harder to get that information (unless it's TypeScript I guess)
I’m trying to require a npm library and I’m getting this error while compiling with shadow-cljs:
Closure compilation failed with 1 errors
--- node_modules/@voxeet/voxeet-web-sdk/dist/voxeet-sdk.js:204
This code cannot be converted from ES6. class expression that cannot be extracted
Is there a way to work around this or does this mean I can’t use this library?@rberger you can set :compiler-options {:output-feature-set :es6}
probably. then it won't try to compile down to es5.
@thheller Still getting the same error. Here’s my shadow-cljs,edn:
{:deps true
:nrepl {:port 8777}
:builds {:app {:target :browser
:output-dir "resources/public/js/compiled"
:asset-path "/js/compiled"
:modules {:app {:init-fn omnyway-labs.voxeet-basic.core/init
:preloads [devtools.preload
day8.re-frame-10x.preload]}}
:dev {:compiler-options {:compiler-options {:output-feature-set :es6}
:closure-defines {re-frame.trace.trace-enabled? true
day8.re-frame.tracing.trace-enabled? true}}}
:devtools {:http-root "resources/public"
:http-port 8280
}}}}
And I’m compiling with: shadow-cljs -A:dev compile app
note this means your output requires a runtime that actually supports es6. so this will mean really old browsers will now likely fail.
https://caniuse.com/#feat=es6-class 5.91% apparently 😛
I know this will sound like an odd request but I need to be able to add a handler for functions in Transit. It works perfectly in clj, but in cljs I cannot figure it out. Fn, IFn, js/Function
, nothing seems to work, and when a handler is not found then :transform is not called
(on write, obviously)
Oh, actually, it works with MetaFn
(those functions will always have metadata). Once again, I am embarrassed about how long it took me to figure it out...
Cljs has been tiring me all day today 😅