This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-03-29
Channels
- # beginners (24)
- # boot (6)
- # cider (22)
- # cljsjs (1)
- # cljsrn (12)
- # clojars (3)
- # clojure (170)
- # clojure-china (2)
- # clojure-dusseldorf (18)
- # clojure-finland (1)
- # clojure-italy (32)
- # clojure-nl (1)
- # clojure-russia (65)
- # clojure-sanfrancisco (1)
- # clojure-spec (21)
- # clojure-uk (46)
- # clojurescript (92)
- # clojutre (1)
- # clr (7)
- # cursive (7)
- # datomic (6)
- # dirac (49)
- # emacs (17)
- # events (1)
- # funcool (20)
- # hoplon (6)
- # job (1)
- # jobs (1)
- # keechma (2)
- # leiningen (6)
- # lumo (74)
- # off-topic (15)
- # om (7)
- # onyx (40)
- # overtone (4)
- # pedestal (8)
- # powderkeg (4)
- # proton (2)
- # protorepl (2)
- # re-frame (18)
- # reagent (24)
- # ring-swagger (3)
- # rum (15)
- # slack-help (1)
- # spacemacs (20)
- # uncomplicate (62)
- # unrepl (29)
- # untangled (10)
- # yada (10)
@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.@rgdelato that's weird, can you show me how you're compiling your code?
I'm using the same command from the quick start: java -cp cljs.jar:src clojure.main build.clj
@rgdelato sorry I should have been more precise: can you show me the contents of build.clj
?
;; 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"})
yeah that's weird. trying locally
@rgdelato yeah works here
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*
what does clojurescript version print?
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=>
so it should work
can you add :verbose true
to your compiler options and paste the compilation output?
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
that doesn't make any sense, I can't repro here
@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
I don't see a node_modules
folder
no, but the CLJS compiler should install that for you
Installing Node.js dependencies
seems to have finished successfully?
I wonder if it's just because we're not capturing the errors when we shell out
can you try to npm install module-deps [email protected]
?
it wouldn't work without a package.json
, but doing npm init && npm install module-deps [email protected]
and then building works!
npm install
should work without a package.json
just tried again, it's not creating a node_modules directory for me without the package.json file
npm --version
?
so I'm on 4.1.2 and it works
perhaps that's the problem I don't know
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.
I never quite realized how annoying the clj repl startup time is until seeing how fast lumo is.
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.
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).
@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.
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.
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.
@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.
Basically, I pump maps through a transducer pipeline, where each stage enhances the map with additional keys (results of computations).
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.
I'm using taoensso.tufte
in the meantime, but this requires quite a bit of manual instrumentation, not alwas possible.
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.
I’ve previously had success with simple calls to time
, but that may be non-trivial to apply to a transducer pipeline.
@jrychter No way around profiling, best is do to an advanced pseudo build. Use js/console.profile
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?
I mean, apart from providing a parameter from when calling 🙂
@reefersleep (boolean (:ns &env))
returns true
when in cljs
Neat! Thanks @moxaj , I'll give it a go!
@reefersleep also check out this library: https://github.com/cgrand/macrovich
Much obliged, @miikka
@moxaj : &env isn't bound to anything, it seems
So I get an exception
(when calling from cljs : )
@reefersleep &env
should be available in your macro
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.
• 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.
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 😄
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.
Never mind, I think I figured it out.
I seemed to have to delete the output first.
I added :output-dir "out"
(since cljsbuild defaults to "target/cljsbuild-compiler-X") and :optimizations :none
(since cljsbuild defaults to :whitespace
).
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.
@U066EC4ES you’re famous!
Awesome! Glad you enjoyed it @mattgeb!
Oh, sweet. Thanks for the cool tutorial! Made web dev seem approachable instead of a huge mess.
@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!
e.g:
(js/React.createElement
js/DatePicker #js {:onBlur #(
;; how to get to `this` of DatePicker ?
)})
@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"
(I noticed that is not on the CLJS cheatsheet...)
@peterschwarz oh yeah I forgot about this-as
, thanks!
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
@ag if you’re using html5 datepicker input (”datetime-local”) you can do :on-blur #(-> % .-target .-value)