Fork me on GitHub
#clojurescript
<
2017-03-29
>
rgdelato04:03:04

@anmonteiro So I tried running script/uberjar off of clojurescript master, and then I used the resulting cljs.jar to try to build the code from your blog post and I'm unfortunately still getting this error:

Caused by: clojure.lang.ExceptionInfo: No such namespace: left-pad, could not locate left_pad.cljs, left_pad.cljc, or Closure namespace "left-pad" in file src/hello_world/core.cljs {:tag :cljs/analysis-error}
...I figured using the jar directly was the best way to get a minimal repro on my end.

anmonteiro04:03:06

@rgdelato that's weird, can you show me how you're compiling your code?

rgdelato04:03:39

I'm using the same command from the quick start: java -cp cljs.jar:src clojure.main build.clj

anmonteiro04:03:04

@rgdelato sorry I should have been more precise: can you show me the contents of build.clj?

rgdelato04:03:16

;; build.clj
(require '[cljs.build.api :as b])

(b/build "src"
  {:optimizations :none
   :main 'hello-world.core
   :npm-deps {:left-pad "1.1.3"} ;; NEW
   :output-to "main.js"})

rgdelato04:03:37

only change should be the namespace from example to hello-world

anmonteiro04:03:08

yeah that's weird. trying locally

anmonteiro04:03:00

can you try this?

$ java -cp src:cljs.jar clojure.main
Clojure 1.8.0
user=> (require '[cljs.util :as u])
nil
user=> u/*clojurescript-version*

anmonteiro04:03:06

what does clojurescript version print?

rgdelato04:03:10

java -cp src:cljs.jar clojure.main
Clojure 1.8.0
user=> (require '[cljs.util :as u])
nil
user=> u/*clojurescript-version*
{:major 1, :minor 9, :qualifier 513}
user=>

anmonteiro04:03:37

so it should work

anmonteiro04:03:58

can you add :verbose true to your compiler options and paste the compilation output?

rgdelato04:03:28

Apologies, this is pretty long and Slack isn't giving me the little option below to turn it into a snippet...

java -cp cljs.jar:src clojure.main build.clj
Installing Node.js dependencies
Reading analysis cache for jar:file:/Users/ryandelatorre/hello_world/cljs.jar!/cljs/core.cljs
Compiling src/hello_world/core.cljs
Exception in thread "main" clojure.lang.ExceptionInfo: failed compiling file:src/hello_world/core.cljs {:file #object[java.io.File 0x73aff8f1 "src/hello_world/core.cljs"]}, compiling:(/Users/ryandelatorre/hello_world/build.clj:4:1)
	at clojure.lang.Compiler.load(Compiler.java:7391)
	at clojure.lang.Compiler.loadFile(Compiler.java:7317)
	at clojure.main$load_script.invokeStatic(main.clj:275)
	at clojure.main$script_opt.invokeStatic(main.clj:335)
	at clojure.main$script_opt.invoke(main.clj:330)
	at clojure.main$main.invokeStatic(main.clj:421)
	at clojure.main$main.doInvoke(main.clj:384)
	at clojure.lang.RestFn.invoke(RestFn.java:408)
	at clojure.lang.Var.invoke(Var.java:379)
	at clojure.lang.AFn.applyToHelper(AFn.java:154)
	at clojure.lang.Var.applyTo(Var.java:700)
	at clojure.main.main(main.java:37)
Caused by: clojure.lang.ExceptionInfo: failed compiling file:src/hello_world/core.cljs {:file #object[java.io.File 0x73aff8f1 "src/hello_world/core.cljs"]}
	at clojure.core$ex_info.invokeStatic(core.clj:4617)
	at cljs.compiler$compile_file$fn__3349.invoke(compiler.cljc:1439)
	at cljs.compiler$compile_file.invokeStatic(compiler.cljc:1408)
	at cljs.closure$compile_file.invokeStatic(closure.clj:486)
	at cljs.closure$fn__4403.invokeStatic(closure.clj:555)
	at cljs.closure$fn__4403.invoke(closure.clj:551)
	at cljs.closure$fn__4345$G__4338__4352.invoke(closure.clj:441)
	at cljs.closure$compile_sources$iter__4529__4533$fn__4534.invoke(closure.clj:905)
	at clojure.lang.LazySeq.sval(LazySeq.java:40)
	at clojure.lang.LazySeq.seq(LazySeq.java:49)
	at clojure.lang.Cons.next(Cons.java:39)
	at clojure.lang.RT.next(RT.java:688)
	at clojure.core$next__4341.invokeStatic(core.clj:64)
	at clojure.core$dorun.invokeStatic(core.clj:3033)
	at clojure.core$doall.invokeStatic(core.clj:3039)
	at cljs.closure$compile_sources.invokeStatic(closure.clj:900)
	at cljs.closure$build.invokeStatic(closure.clj:2281)
	at cljs.build.api$build.invokeStatic(api.clj:201)
	at cljs.build.api$build.invoke(api.clj:189)
	at cljs.build.api$build.invokeStatic(api.clj:192)
	at cljs.build.api$build.invoke(api.clj:189)
	at user$eval24.invokeStatic(build.clj:4)
	at user$eval24.invoke(build.clj:4)
	at clojure.lang.Compiler.eval(Compiler.java:6927)
	at clojure.lang.Compiler.load(Compiler.java:7379)
	... 11 more
Caused by: clojure.lang.ExceptionInfo: No such namespace: left-pad, could not locate left_pad.cljs, left_pad.cljc, or Closure namespace "left-pad" in file src/hello_world/core.cljs {:tag :cljs/analysis-error}
	at clojure.core$ex_info.invokeStatic(core.clj:4617)
	at cljs.analyzer$error.invokeStatic(analyzer.cljc:641)
	at cljs.analyzer$error.invoke(analyzer.cljc:641)
	at cljs.analyzer$error.invokeStatic(analyzer.cljc:643)
	at cljs.analyzer$analyze_deps.invokeStatic(analyzer.cljc:1895)
	at cljs.analyzer$ns_side_effects.invokeStatic(analyzer.cljc:3133)
	at cljs.analyzer$ns_side_effects.invoke(analyzer.cljc:3127)
	at cljs.analyzer$analyze_STAR_$fn__2190.invoke(analyzer.cljc:3224)
	at clojure.lang.PersistentVector.reduce(PersistentVector.java:341)
	at clojure.core$reduce.invokeStatic(core.clj:6544)
	at cljs.analyzer$analyze_STAR_.invokeStatic(analyzer.cljc:3221)
	at cljs.analyzer$analyze.invokeStatic(analyzer.cljc:3241)
	at cljs.compiler$emit_source.invokeStatic(compiler.cljc:1277)
	at cljs.compiler$compile_file_STAR_$fn__3326.invoke(compiler.cljc:1350)
	at cljs.compiler$with_core_cljs.invokeStatic(compiler.cljc:1178)
	at cljs.compiler$compile_file_STAR_.invokeStatic(compiler.cljc:1341)
	at cljs.compiler$compile_file$fn__3349.invoke(compiler.cljc:1429)
	... 34 more

anmonteiro04:03:58

that doesn't make any sense, I can't repro here

anmonteiro04:03:49

@rgdelato please do the following: 1. wipe your out folder and main.js and try again 2. paste the contents of your core.cljs file, as well as your directory structure

anmonteiro04:03:00

I don't see a node_modules folder

rgdelato04:03:13

o.o ...sorry, I'm also supposed to npm install as well?

anmonteiro04:03:27

no, but the CLJS compiler should install that for you

anmonteiro04:03:52

Installing Node.js dependencies seems to have finished successfully?

rgdelato04:03:54

I only got a main.js and an /out directory

rgdelato04:03:17

yeah, doesn't seem to be any errors on Installing Node.js dependencies

anmonteiro04:03:35

I wonder if it's just because we're not capturing the errors when we shell out

anmonteiro04:03:05

can you try to npm install module-deps [email protected]?

rgdelato04:03:38

it wouldn't work without a package.json, but doing npm init && npm install module-deps [email protected] and then building works!

anmonteiro04:03:17

npm install should work without a package.json

rgdelato04:03:43

just tried again, it's not creating a node_modules directory for me without the package.json file

anmonteiro04:03:37

npm --version?

rgdelato04:03:54

npm --version
3.10.9

anmonteiro04:03:06

so I'm on 4.1.2 and it works

anmonteiro04:03:12

perhaps that's the problem I don't know

rgdelato04:03:29

okay, I'll give that a try. sorry for being a pain 😞

rgdelato04:03:43

I'm really really sorry, I figured out the problem. o.o ...there was another node_modules directory further up the file structure and it was installing there instead. That's why adding a package.json to my current directory fixed the problem.

dominicm07:03:35

We've had that problem

dominicm07:03:37

No idea if there's a simple way to force npm into a particular directory

qqq08:03:36

lumo is amazing

qqq08:03:44

I'm looking for a reason to script / write a desktop app just so I can use lumo.

qqq08:03:56

I never quite realized how annoying the clj repl startup time is until seeing how fast lumo is.

qqq08:03:14

Did I mention lumo is amazing?

jimmy11:03:44

hi guys I have a question regarding advanced compilation, I have used ^:export meta in the main function. But it's not where to be found after being compiled in :advanced mode. :simple mode works just fine.

jrychter11:03:36

So, after about a year of having a complex app in production, for the first time ever, I need to do some ClojureScript profiling (this shows how fantastic ClojureScript is, btw). I have a place in my app where I spend significant time. It's pretty generic .cljc code manipulating data structure and doing computations. Any hints on how to approach this? I tried the Chrome profiler, but it doesn't seem to be that great (as an example, I'd like to get a filtered list of functions in one namespace, with total time spent in each).

jrychter11:03:22

@rgdelato Oh, node_modules — this one always drives me nuts. No build tool should ever do anything (or depend on anything) in a directory further up from the one its being run from.

miikka11:03:31

For what it's worth, I've found the Chrome's timeline to be slightly more useful than the profiler when I'm dealing with code where I don't have a good idea of what's slow. But no idea how to drill into a single module.

miikka11:03:28

Also when dealing with lazy sequences, forcing them with doall can be useful. It does not make it faster, but it makes the profiles easier to read when the sequence computation is not interspersed with the sequence-consuming computation.

jrychter11:03:27

@miikka Thanks. In my case, I mostly use transducers. And it seems I'm spending most time in hash map updates, but it's quite difficult to see where exactly and infer what I could do about it.

jrychter11:03:55

Basically, I pump maps through a transducer pipeline, where each stage enhances the map with additional keys (results of computations).

jrychter11:03:50

Also, just to provide some perspective: it's impressive how well it works. This is about pricing electronics projects, there are 50 components, each one has 40-50 offers, and each offer has quantity price breaks, minimal quantities, and other restrictions. ClojureScript is able to go through all this in ~100ms on my machine, which is really good. Still, not everyone has a fast computer, and I'd like to have this work slightly faster.

jrychter11:03:41

I'm using taoensso.tufte in the meantime, but this requires quite a bit of manual instrumentation, not alwas possible.

miikka11:03:05

If you use maps as records, it maybe worthwhile to use defrecord or deftype instead

miikka11:03:22

Setting mutable fields of records created with deftype compiles down to setting properties of JS objects. It's not very idiomatic CLJS, but it's much faster than updating a map.

Rachel Westmacott12:03:27

I’ve previously had success with simple calls to time, but that may be non-trivial to apply to a transducer pipeline.

rauh12:03:19

@jrychter No way around profiling, best is do to an advanced pseudo build. Use js/console.profile

jrychter12:03:04

@miikka That's an interesting suggestion — thanks!

reefersleep12:03:38

When I am inside a defmacro in a cljc file that I call from cljs and use the #? reader conditional, it always hits the :clj condition.... Which is fair enough, since I guess we're "in" Clojure when executing the macro. It poses a problem for me, however, since I want to do two different things based on the environment of the caller. Is there an easy solution for this that I just don't see?

reefersleep12:03:18

I mean, apart from providing a parameter from when calling 🙂

moxaj12:03:23

@reefersleep (boolean (:ns &env)) returns true when in cljs

reefersleep12:03:52

Neat! Thanks @moxaj , I'll give it a go!

reefersleep12:03:59

@moxaj : &env isn't bound to anything, it seems

reefersleep12:03:12

So I get an exception

reefersleep12:03:38

(when calling from cljs : )

moxaj12:03:39

@reefersleep &env should be available in your macro

reefersleep12:03:46

I'm using &env in the macro... maybe I've quoted stuff wrongly in the macro. Going to try and fiddle with it a bit.

cgrand13:03:25

It’s sort of why macros/case works quoted or not.

cgrand13:03:13

• sometimes you don’t have &env because you are quoted, and escaping quotation may require manually gensyming some symbols • sometimes you don’t have &env because you are in a helper fn which is not lexically scoped by the macro def.

reefersleep14:03:55

Cheers @cgrand , I hit your second case purposefully by adding a helper fn to determine &env, and afterwards thought that I had removed it, and couldn't figure out what was wrong... I'm branching succesfully on &env now, so thanks all around 😄

tech_hutch16:03:28

What's the proper way to set up lein when using node? I have :output-to "main.js", :target :nodejs like my build script before setting up lein, but compiling doesn't seem to output anywhere.

tech_hutch19:03:35

Never mind, I think I figured it out.

wiseman20:03:26

tech_hutch: https: //imgur.com/a/OnmOl

tech_hutch20:03:18

I seemed to have to delete the output first.

tech_hutch20:03:38

I added :output-dir "out" (since cljsbuild defaults to "target/cljsbuild-compiler-X") and :optimizations :none (since cljsbuild defaults to :whitespace).

mattgeb21:03:02

Hey, so, I haven't really done much webdev. But, I really like Clojure, and I feel like Clojurescript (especially combined with Node or just a Clojure backend, like in this cool tutorial I followed: http://blog.testdouble.com/posts/2016-01-21-isomorphic-clojurescript.html ), I could get up and running in a relatively straightforward way. Was wondering how realistic it is to get started with web dev with basically just Clojurescript? Most of the cljs tutorials I've seen seem to assume some web experience, but I can't tell if I need to learn things in that order or not.

andrewvida23:03:22

Awesome! Glad you enjoyed it @mattgeb!

mattgeb23:03:00

Oh, sweet. Thanks for the cool tutorial! Made web dev seem approachable instead of a huge mess.

shaun-mahood21:03:40

@mattgeb I think it's reasonably realistic, but you will probably have to fill in quite a few gaps along the way. Ask a lot of questions in #beginners and go for it - you'll at least have fun!

mattgeb21:03:29

Cool, thanks! 🙂

ag22:03:31

when using js/React.createElement how do I access this from inside the handlers?

ag22:03:40

e.g:

(js/React.createElement
 js/DatePicker #js {:onBlur #(
                              ;; how to get to `this` of DatePicker ?
                      )})

peterschwarz22:03:15

@ag Use the this-as macro:

cljs.user=> (def o #js {:foo (fn[] (this-as this (.-bar this))) :bar "hello"})
#'cljs.user/o
cljs.user=> (.foo o)
"hello"

peterschwarz22:03:18

(I noticed that is not on the CLJS cheatsheet...)

ag22:03:21

@peterschwarz oh yeah I forgot about this-as, thanks!

ag22:03:10

actually, has anyone used HackerOne “react-datepicker”? https://github.com/Hacker0x01/react-datepicker, I can’t find a way to handle onBlur the way I want. Specifically can’t figure out how to access the date value in the handler

emilyseibert22:03:41

@ag if you’re using html5 datepicker input (”datetime-local”) you can do :on-blur #(-> % .-target .-value)

ag22:03:54

That's not the correct value though. It's ok. I have figured it out.

ag22:03:31

It's in this.props.selected