Fork me on GitHub
#clojurescript
<
2020-04-26
>
J01:04:52

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.

theeternalpulse01:04:38

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.

john02:04:49

@theeternalpulse It doesn't auto-refresh the browser for you

theeternalpulse02:04:50

even after a browser refresh it doesn't seem to take

theeternalpulse02:04:18

I do notice this in the log

java.lang.AssertionError: Assert failed: :nodejs target with :none optimizations requires a :main entry

Umar Daraz05:04:09

@theeternalpulse Please share if you found solution to this problem. I m just starting out with clojurescript and stuck at this issue. thanks

theeternalpulse14:04:15

@U9S1URQ4T just found this https://clojure.atlassian.net/browse/CLJS-3238 seems to be a blocker, so it's being looked at.

theeternalpulse23:04:03

Seems to be closed as well, look forward to the hotfix

theeternalpulse03:04:18

@U9S1URQ4T try org.clojure/clojurescript {:mvn/version "1.10.748"}

Umar Daraz04:04:25

thank you @theeternalpulse. It is super helpful. I m loving the clojure community.

theeternalpulse02:04:45

my build.edn does contain a :main entry, but I'm using the :bundle target

john02:04:30

I'm not getting that, so yeah, that might be your problem

john02:04:37

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.

dpsutton02:04:27

That node target looks suspicious

theeternalpulse02:04:44

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"]}}

theeternalpulse02:04:27

using cljs 1.10.741

theeternalpulse02:04:31

pretty much everything other than the watch is from the guide

theeternalpulse02:04:43

and the app-name of course

john03:04:56

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: ...

john03:04:29

@theeternalpulse are you using shadow?

theeternalpulse03:04:55

no this is from the recent guide for using webpack

john03:04:21

Cause I think shadow uses modules

theeternalpulse03:04:23

I know there are cljs-watch libraries

Spaceman04:04:05

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?

Spaceman04:04:32

one solution is doing (http/get (str (:base-url config) "/some-route")) and config map contains the correct `base-url`

Spaceman04:04:44

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

Spaceman05:04:33

That's fine, but how would shadow know whether it's running in production or development?

Spaceman05:04:43

isn't the build the same, i.e., :app in both production and development in my case?

Spaceman05:04:43

how would shadow know the difference?

john05:04:20

You put different defines in different builds

john05:04:36

I've never really used shadow but I'd assume you can have different builds for prod and dev

kimim06:04:29

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."]))))

p-himik07:04:43

Works just fine for me.

p-himik07:04:02

Are you sure that the build is fine and this code is exactly the one that ends up on the page?

kimim08:04:15

For me, this function just don't re-render, it will not change.

p-himik08:04:23

Does the :on-click handler work? Try to put js/console.log somewhere in there to check.

kimim08:04:05

on-click event is trigger several times, when i click the text.

kimim08:04:54

But it works if I change clicked to a app-db variable

p-himik08:04:09

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.

Eamonn Sullivan08:04:40

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?

dpsutton09:04:12

can you post your source file?

dpsutton09:04:12

/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"

Eamonn Sullivan09:04:03

I'm literally going through the Quick Start. That's all I have in the source.

dpsutton09:04:18

anything in your deps.edn file?

Eamonn Sullivan09:04:35

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.

Eamonn Sullivan09:04:57

It's grown a bit large. Let me do a gist (if I remember how to do that)

dpsutton09:04:12

don't need the whole thing

dpsutton09:04:20

i just mean your local deps.edn

dpsutton09:04:27

in this directory

Eamonn Sullivan09:04:40

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.

dpsutton09:04:32

gotcha. just making sure to check the basics since like you said there aren't many pieces involved here

Eamonn Sullivan09:04:27

I see I also have a ~/.cljs directory, but there's nothing in it but .aot_cache/1.10.742

dpsutton09:04:38

maybe remove the .cpache dir?

dpsutton09:04:58

might be some stale stuff laying around?

dpsutton09:04:44

.cpcache sorry (typo above)

dpsutton09:04:08

ahh, i get the same result with 742. seems a bug in cljs

dpsutton09:04:20

use "1.10.597" instead

Eamonn Sullivan09:04:30

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?

Eamonn Sullivan09:04:38

Where would I raise it/

dpsutton09:04:37

i'm making a ticket now

dpsutton09:04:52

i've done the webpack one and it works fine if you're interested but for sure stay back for node for now

dpsutton09:04:02

sorry about that issue. that's a bummer when you're trying to learn

Eamonn Sullivan09:04:43

No worries. Thanks for the quick response!

dpsutton09:04:34

are you requiring goog.dom in that file?

Frederik09:04:42

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!

ingesol10:04:11

@dnolen Thanks for clarifying about namespaces as strings and how to invoke them! I will test today

dnolen10:04:32

@ingesol file a bug if the constructor pattern on the invokeable doesn't work, thanks

Adam Helins12:04:05

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"

Ahmed Hassan12:04:04

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

tatut12:04:00

for example with cljs-time formatting

Ahmed Hassan12:04:52

(defn inst->dstring [dinst]
  (str (.getFullYear dinst) "-" (cl-format nil "~2,'0d" (inc (.getMonth dinst))) "-" (cl-format nil "~2,'0d" (.getDate dinst))))

Ahmed Hassan12:04:16

Used cljs.pprint/cl-format to do this

Ahmed Hassan12:04:27

I want to do it in better way.

Eamonn Sullivan13:04:23

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.)

Chris O’Donnell13:04:51

@eamonn.sullivan I believe datascript publishes an npm library. That could serve as an example.

Eamonn Sullivan13:04:22

Perfect, thanks!

Felipe Marques13:04:31

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!

dnolen14:04:29

@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

dnolen14:04:30

you can easily search for the reader tests via Github

Adam Helins15:04:39

@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".

dnolen15:04:27

ah right that would be painful

dnolen15:04:40

hopefully you got it working

Adam Helins15:04:25

Yes, as simple as removing the println form...

Alex15:04:31

Hey guys, I was wondering how you guys get a subset of a map with goog.object.

Eamonn Sullivan15:04:59

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?

dnolen15:04:21

@eamonn.sullivan I nearly just always use whatever is in the JS environment instead of looking for a wrapper

dnolen15:04:16

@alexander.890 there's not one function for that

dnolen15:04:50

could probably use goog.object/filter which returns an object

Alex15:04:41

@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.?

Alex15:04:33

Thanks, I'll take a look.

dnolen15:04:45

that's for read only operations

dnolen15:04:30

if you need to update, then you would have a lot more work todo - but I wouldn't really recommend that anyway

dnolen15:04:18

in all my years of doing ClojureScript doing more than cljs-bean hasn't really seemed very worthwhile

mfikes15:04:33

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.

Alex15:04:34

I'll keep that in mind, thanks.

Kevin18:04:27

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.

lilactown18:04:42

Can you convert it to a CLJS data structure then view it?

Kevin18:04:56

It's just EDN

Kevin18:04:13

But it would be nice if there was some kind of UI library I could use to display it

thheller19:04:59

if you use shadow-cljs you can try the Inspect feature

Kevin20:04:59

Ah awesome! This is exactly what I needed. Thank you 🙂

ingesol19:04:07

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

ingesol19:04:55

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"]}}

thheller19:04:20

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

ingesol20:04:52

thanks! I’ll have a look.

dnolen19:04:56

@ingesol fixed in master

dnolen19:04:05

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

dnolen19:04:50

just did a quick audit - and this seems to be close to the last case - if not the last case

ingesol19:04:01

@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.

dnolen19:04:37

allowing the transition to be straightforward is important

dnolen19:04:13

there'll probably be release this coming Friday including all the various things that have come up as people try out the new changes

ingesol19:04:24

@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?

ingesol19:04:46

Great! (the release next friday), Looking forward to trying again.

dnolen19:04:59

@ingesol what you were doing before would still work

dnolen19:04:59

nothing is forcing you to use :output-to as the entry point for the bundler

dnolen19:04:31

you could supply your own index.js that does the setup as before, and that file requires :output-to

dnolen19:04:59

works for dev / prod as long as nothing in index.js needs to call into the CLJS

dnolen20:04:14

if you need to do that for some reason - then in dev mode you will need to wait for the main ns to load

dnolen20:04:29

the :bundle target is intentionally steps back from these kinds of choices because it's impossible to predict the scenario

dnolen20:04:42

this was informed by my desire to make it work for Webpack and Metro at the same time

dnolen20:04:49

making too many choices is problematic

ingesol20:04:38

I see, that’s simple enough, just “wrap” the generated index.js Nice!

dnolen20:04:58

@ingesol if you're using deps.edn it would be best to try master (to test) rather than waiting for release

dnolen20:04:20

would be easier for to me continue to plug any further holes you may discover

ingesol20:04:42

Using lein actually. I’ll see if I can find time to convert project to test last bits

dnolen20:04:24

only used this a couple of times but maybe that can make it easier for you

ingesol20:04:12

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.

dnolen20:04:07

I'm assuming just install that node module and try to require to repro?

ingesol20:04:21

(require [some-other-npm]) and (some-other-npm args) worked. Could be an issue with that specific module, will test some more

ingesol20:04:11

retesting that now, to verify

ingesol20:04:46

Actually, I think I was wrong. Lots of debugging today, so this error was on me. Namespace doing this require compiles without error now.

dnolen20:04:41

appears to work fine

dnolen20:04:45

I didn't actually run the code

dnolen20:04:55

but the require is fine, I can instantiate the namespace

dnolen20:04:08

no warnings, no complaints from the compiler

ingesol20:04:25

yes, I found that too, see message above. Sorry about that, and thanks for checking

Takis_20:04:40

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

dnolen20:04:43

@takis_ probably a better question for the #cursive channel

dnolen20:04:44

more generally this is a problem and will probably be addressed in a release in the near future for standard browser API

dnolen20:04:04

Cursive handles this stuff in it's own way though so can't offer any more info

Takis_20:04:38

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 🙂

dnolen20:04:22

@takis_ to be clear autocomplete works for Google Closure Library

dnolen20:04:35

this stuff protects you from browser quirks, and that stuff autocompletes

dnolen20:04:50

and we provide doc and validation for usage now

dnolen20:04:04

so instead of going direct to the browser apis, you could use this stuff for autocomplete

Takis_20:04:18

i want to use clojurescript and node.js , mongodb

dnolen20:04:46

hrm, yeah ok not sure what the status of Node.js autocomplete is in Cursive

Takis_20:04:44

we will see thank you alot 🙂

Takis_20:04:26

in emacs this is possible?

Takis_20:04:48

or any other ide

dnolen20:04:46

No idea, I just use Cursive myself - Emacs probably not since we dont supply that information yet

dnolen20:04:12

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)

Takis_20:04:48

thank you alot for the information i am totally new

rberger20:04:28

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?

thheller20:04:24

@rberger you can set :compiler-options {:output-feature-set :es6} probably. then it won't try to compile down to es5.

rberger20:04:46

Thanks, trying

rberger20:04:31

@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

rberger20:04:17

Oh I see stupid error

thheller20:04:21

you also probably want to always enable that. otherwise it'll fail for release

rberger20:04:36

Ok, thanks. That did get rid of the ES6 issue. And thanks for the tip on release.

thheller20:04:35

note this means your output requires a runtime that actually supports es6. so this will mean really old browsers will now likely fail.

rberger20:04:15

Who runs old browsers 🙂

Adam Helins22:04:48

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

Adam Helins22:04:16

(on write, obviously)

dnolen22:04:33

(extend-type function ...)

dnolen22:04:00

it won't work for IFn

Adam Helins23:04:34

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 😅