This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-06-08
Channels
- # atlanta-clojurians (1)
- # beginners (116)
- # cider (70)
- # cljs-dev (11)
- # cljsrn (2)
- # clojure (218)
- # clojure-italy (7)
- # clojure-nl (14)
- # clojure-nlp (11)
- # clojure-spec (8)
- # clojure-uk (113)
- # clojurescript (86)
- # core-async (14)
- # cursive (24)
- # datomic (64)
- # duct (1)
- # emacs (3)
- # fulcro (20)
- # graphql (10)
- # jobs-rus (1)
- # london-clojurians (1)
- # luminus (1)
- # nyc (1)
- # off-topic (24)
- # onyx (1)
- # parinfer (1)
- # pedestal (14)
- # portkey (11)
- # re-frame (36)
- # reagent (9)
- # reitit (5)
- # ring (1)
- # shadow-cljs (197)
- # spacemacs (21)
- # specter (22)
- # sql (15)
- # tools-deps (5)
Am I doing something wrong?
clj -m cljs.main -co "{:foreign-libs [{:global-exports '{global.test global}}]}" -re node -r
Exception in thread "main" java.lang.RuntimeException: Map literal must contain an even number of forms
:global-exports
is supposed to be a quoted map of namespaces to global exports, right?
...I was about to say that it does the same thing with a file. Then I tried the file without the quote. Thanks, @bhauman!
Bah. I should've solved the online requirement of cljsbuild earlier. Now I'm stuck working in a train with mobile connection that works... sometimes. If the problem is in the lein side (as I thought) and hairy to untangle, what are the alternatives for building cljs files?
Noob question. Trying to build with lein-cljsbuild and all my deps seem to end up in app.js but not my own sources. What am I doing wrong?
{:id "not-min"
:source-paths ["src/cljs" "src/cljc"]
:compiler {:main lipas.ui.core
:output-to "resources/public/js/compiled/app.js"
:optimizations :whitespace
:closure-defines {goog.DEBUG false}
:pretty-print false}}
Iāve been developing this with figwheel so far and it works nicely. However Iām now trying to create a js-file that I can upload to server
Itās also very like that Iāve understood something wrong. Iām now assuming that all JS would be emitted to single file (app.js)
Now app.js contains thousands of rows from my deps but nothing from my own sources (checked with grep). However all my code + deps was compiled under target/cljsbuild-compiler-1/ā¦
into separate files. Why is my stuff missing from app.js?
Iām supposed to demo this in 10min š It wouldāve been cool to have it on internet so people could try with their own devices. But maybe Iāll stick with figwheel & screenshare this time.
Reading now through https://github.com/clojure/clojurescript-site/blob/master/content/reference/compiler-options.adoc
Heh, updated to latest clojurescript and got better error message from the compiler. I had a file with bad name local-storage.cljs
instead of local_storage.cljs
. I guess thatās why it failed earlier.. though the last line in output was always āSuccessfully compiled ā¦.ā š
that result string is from cljsbuild, itās odd that you didnāt get an exception during build though
Odd indeed
[email protected]:/usr/src/app# lein cljsbuild once not-min
Compiling ClojureScript...
[email protected]:/usr/src/app#
This was with 1.9.908 EDIT: looking at the output it doesnāt say āsuccessā even though I earlier claimed so. Now thinking about it.. Itās possible that my STDERR was going to /dev/null or something since I was playing with a bash session in Docker.
And with 1.10.238
Compiling ClojureScript...
Compiling "resources/public/js/compiled/app-min.js" from ["src/cljs" "src/cljc"]...
Jun 08, 2018 2:18:47 PM com.google.javascript.jscomp.LoggerErrorManager println
SEVERE: /Users/vaotjuha/lipas/lipas/webapp/target/cljsbuild-compiler-1/lipas/ui/core.js:5: ERROR - required "lipas.ui.local_storage" namespace never provided
goog.require('lipas.ui.local_storage');
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Ahhh. Hereās another weird attempt when run on host (MacOS)
lein clean && lein cljsbuild once not-min
Compiling ClojureScript...
Compiling "resources/public/js/compiled/app.js" from ["src/cljs" "src/cljc"]...
Jun 08, 2018 12:41:26 PM com.google.javascript.jscomp.LoggerErrorManager println
SEVERE: /Users/vaotjuha/lipas/lipas/webapp/target/cljsbuild-compiler-1/cljs/core.js:3579: ERROR - Parse error. primary expression expected
case ##Inf:
^
Jun 08, 2018 12:41:26 PM com.google.javascript.jscomp.LoggerErrorManager printSummary
WARNING: 1 error(s), 0 warning(s)
ERROR: JSC_PARSE_ERROR. Parse error. primary expression expected at /Users/vaotjuha/lipas/lipas/webapp/target/cljsbuild-compiler-1/cljs/core.js line 3579 : 6
Successfully compiled "resources/public/js/compiled/app.js" in 18.084 seconds.
@valtteri I'd check the tools.reader
version. See https://stackoverflow.com/questions/48039878/cljs-core-cljs-line-988-col-14-no-reader-function-for-tag-inf/48327231#48327231
But, in the above, it is as if ClojureScript is being put in your JavaScript file? Odd.
Iām not absolutely sure what was going on there because I didnāt know what I was doing. š But I think that the problem was indeed that there was a file with bad name and the latest clojurescript compiler was able to provide useful error which lead me to right direction. The confusion game from lein-cljsbuild telling that build was success even though it failed and error-message was really cryptic from 1.9xxx compiler.
HMmm isnāt tools.reader
shipped with clojurescript? So there shouldnāt be version mismatch unless something pulled me another version somehow?
Hmm or is it actually shipped with clojure.. Anyways my clojure version is ā1.9.0ā
I probably need to figure out how this whole compliation process and related tooling actually works. š
@valtteri Yeah, usually things work correctly with the tools.reader
version that ClojureScript depends upon, and you really only run into trouble if something else in your build tooling causes an older version to be put on the classpath. But, the above sounds like ##Inf
made it into JavaScript, and then Google Closure Compiler failed when it saw it.
I just lately realized that js-libs are nowadays HUGE and :advanced
is really necessary. I added a ui-lib to my project and BOOM 2Mb of js. š
(Actually, as you said, it is not "made it into JavaScript", but just a filenameing confusion)
The JavaScript for cljs.core
is about 1.2 Mb, but typically after :advanced
you end up in the less than 100 Kb range.
I upgraded figwheel, and the code reloading is not working anymore (the compilation happens, but the new code is not loaded). has anyone experienced this?
@roti, try lein clean, remove target/
manually, shift-reload, different browser, roughly in that order
Hmh. How can I mark callback parameters in externs, or otherwise keep the names intact? So I want to pass a callback to external JS lib. That callback will get an object, which has a method I need to call (leaflet marker clusters and the function to create an icon for the cluster)
You could try putting a ^js
type hint in front of the arg, if you have the :infer-externs
compiler option enabled. Eg (fn [^js the-arg] ...)
Ok, so what the inferred externs did was what I had hacked up: set up the methods on Object...
Whoa, If I manage to figure out the right object in the global namespace and extern that, closure compiler knows that the callback is going to get that object and keep the methods as is
So if I put a ^js type hint for a parameter, does that actually mean "This is of type Object" and not just "this is some kind of JS object", and therefore it forces the compiler to treat it as such, even though it's capable of inferring the exact type?
Hmm, no. If I misspell the object, the methods under it are still inferred. I suppose the compiler will just keep all method names under any object in externs, just in case
I'm starting to think that I will just stop thinking about how to make better externs (seems like the project which I inherited is in fact equivalent of having all methods defined on Object) I will just drop them completely and move to cljs-oops
For several months I have been using ^js
hints whenever I encounter an issue with externs, and find that it "just works" and is a nice/lightweight approach. If you have warnings enabled, it will still show warnings for these cases (unless you use shadow-cljs, which directly supports ^js). cljs-oops works too. I just personally prefer to avoid extra libs.
I tried getting the function with goog.object/get and call it then, but then it's called with null this
Is it possible in cljs or even just in JS to get a pem certificate delivered in code only (via ajax, etc) and automatically use that for further REST requests to a server?
I can't find any information suggesting certificates can be installed automatically or used in a browser without explicit user intervention
@ajs wouldnāt it be a security hole if code were able to install certs without user knowledge and/or approval?
i would think so, but i'm working with another team that seems to think this might be possible, even though they haven't done it before
is it possible to use javascriptās async/await in cljs? Iām wanting to use it when writing an abstraction on top of amazon lambda
Iāve set my target to ecmascript2017, but iām not sure how I can define a function as async (and it shows async
/`await` here: https://cljs.github.io/api/compiler-options/language-in)
@dehli no, but you can use promises fairly conveniently with clojurescript. if I have something complicated, I use the alet
macro from the promesa
library which works quite well. that library also has a macro that emulates async/await, but Iāve found it to be a little fragile (and honestly you can do anything with alet
)
you can take a look at https://groups.google.com/forum/#!topic/clojurescript/scUMhU-ctEM for some discussion and https://beta.observablehq.com/@shaunlebron/proposal-generators-and-async-functions-in-clojurescript for a proposal to add them
big discussion thread on some of the challenges here: https://groups.google.com/forum/#!topic/clojurescript/scUMhU-ctEM
Ok, so what the inferred externs did was what I had hacked up: set up the methods on Object...
So if I put a ^js type hint for a parameter, does that actually mean "This is of type Object" and not just "this is some kind of JS object", and therefore it forces the compiler to treat it as such, even though it's capable of inferring the exact type?
@lee.justin.m talking out of ignorance here, why not just use core.async for his async/await needs?
Also I am using core.async, however I needed promises (or async/await) for interop with amazon lambda. Basically just have to convert a core.async channel into something that lambda recognizes
@lockdown- for me personally, my reasons are (1) i do not like the exception handling semantics of core.async, (2) it produces tons of code that is hard to understand and debug, (3) it creates huge stack traces, (4) its way more complex than I need
@lee.justin.m ok, I'm starting to like JS 2018+ š - is not that bad, and there is always lodash/fp
I think the difference in performance of doing immutability in JS(browser) but without the 'persistent' part is very low
FWIW I do not like princess, personally I donāt know why you would want to bother with async/await when you have core.async
If you use it at the edge and for coordination it really not hard to use nor do you encounter serious debugging issues
ran into issues using #?@
reader conditional in (:require ...
section of ns form. Is this a known limitation/bug?
(ns com.foo (:require [cognitect.transit :as t] [cljsjs.big]))
is as small as I can get it
(require 'com.foo)
TypeError: Cannot load script from .cljs_nashorn_repl/goog/undefined
(NO_SOURCE_FILE <eval>:1:0)
(NO_SOURCE_FILE <eval>:1:0)
(NO_SOURCE_FILE <eval>:19:0)
<program> (.cljs_nashorn_repl/com/foo.cljc:5:0)
(NO_SOURCE_FILE <eval>:1:0)
(NO_SOURCE_FILE <eval>:1:0)
(NO_SOURCE_FILE <eval>:19:0)
(NO_SOURCE_FILE <eval>:1:0)
@john to be clear nothing requires async/await as a language feature. You can always use promises
Yeah, but for a particular sort of control flow, when trying to hit the ServiceWorker's cache and blocking on the response, when trying to implement that in cljs... just seemed impossible. My understanding is that a cljs macro that does the same thing the polyfill does over generators, could accomplish something similar?
Yeah, cause I think async/await (at least the polyfilled version) is rewriting the code flow, similar to core.async.