Fork me on GitHub
#shadow-cljs
<
2019-01-24
>
r0man11:01:33

Hello, I'm using the material-components-web-react package with shadow-cljs. I use the material components in the browser, but also on Node.JS for server side rendering. This used to work fine, but now that I'm trying to update the material-components-web-react package I see the following error in Node.JS:

thheller11:01:51

try node require("@material/textfield/constants.js")

r0man11:01:51

The code works fine in the browser. but only fails on Node. I guess this has something to do with the Javascript module system not being compatible. Any ideas how to solve this?

r0man11:01:51

so, this looks like a problem with the package?

thheller11:01:21

there is a flag in node to enable support for ES6 modules

thheller11:01:33

forgot what it was though

thheller11:01:03

but yeah for the browser stuff is rewritten

thheller11:01:19

for node it just uses node which doesn't yet unterstand impot/export without flags

thheller11:01:31

not sure how well this works though

r0man11:01:31

Doesn't seem to work either

thheller11:01:08

ah right it is strict and would require .mjs extension

r0man11:01:49

@thheller Cool, that did the trick! Thank you! 🙂

thheller12:01:45

@neo2551 shadow-cljs by default does not support dependencies per build. you currently can only emulate that when using project.clj or deps.edn

r0man13:01:01

Is there a way to set :closure-defines from the command line? I would like to pass the current git commit into the build.

thheller13:01:29

@r0man see the answer I gave @souenzzo yesterday about clj-run

thheller13:01:45

(defn release [path]
  (-> (shadow/get-build-config :your-build-id)
      (assoc :output-dir path)
      (shadow/release* {})))

thheller13:01:22

just switch to (assoc-in [:clojure-defines 'your.ns/git-commit] the-commit)

r0man13:01:36

perfect, I didn't see that. thanks again!

Jan K13:01:21

Does anyone know a public project that uses the rum library and builds with shadow-cljs? Rum has some cljsjs dependencies on react stuff and I'm not sure how to replace them to make it work, an example would be great.

thheller13:01:50

@jkr.sw shadow-cljs should be taking care of that already. what is the problem?

David Pham13:01:31

@thheller Thanks a lot for your answer

Jan K13:01:01

The JS generated by shadow-cljs doesn't seem to contain react. I don't get any errors in console, but my components aren't rendering. The JS file is about 130 Kb smaller than what falls out of lein-cljsbuild, and build report isn't showing any react/rum code.

thheller13:01:03

do you have any manual cljsjs/* files in your project?

thheller13:01:09

how are you using it?

Jan K13:01:27

At this point I just have rum in my shadow-cljs.edn dependencies (and use rum in my CLJS code).

thheller13:01:30

rum mostly generates code via macro which means the code is in your namespaces not rum namespaces

thheller13:01:27

that should be all you need

Jan K13:01:21

Why is my build report missing react though? I've seen it in the examples

thheller13:01:45

not sure. it should definitely be there

thheller13:01:05

please run shadow-cljs clj-repl and ( "cljsjs/react.cljs")

Jan K13:01:12

that seems to work: #object[java.net.URL 0x55589ef5 "jar:file:/home/jan/.m2/repository/thheller/shadow-cljsjs/0.0.16/shadow-cljsjs-0.0.16.jar!/cljsjs/react.cljs"]

thheller13:01:21

ok that is fine

thheller13:01:43

which build :target do you use? any custom :js-options?

Jan K13:01:52

{:mybuild
  {:target :browser
   :modules {:main {:init-fn my-ui.common/on-js-reload}}}}}

thheller13:01:18

ok that should be fine

thheller13:01:36

no errors in the browser console?

thheller13:01:01

and what are you doing in the :init-fn?

Jan K13:01:16

just a println, I can see that in the console

Jan K13:01:28

No, I mount my rum component in another place at top level of the main cljs file. That's probably the issue, I think I don't have any main cljs file set anywhere in the shadow-cljs build

thheller13:01:59

ah ok. shadow-cljs just isn't including what you want then

thheller13:01:42

{:mybuild
 {:target :browser
  :modules {:main {:entries [your.actual.main-ns]}}
  :devtools
  {:after-load my-ui.common/on-js-reload}}}

thheller13:01:48

your probably want something like that

thheller13:01:01

shadow-cljs only includes whatever is actually required from your config

thheller13:01:36

so you were probably relying on the fact that cljsbuild just includes everything it finds

Jan K14:01:29

Yes I was missing the :entries bit (in lein-cljsbuild I have that as :main). It's working now! Thank you very much!

thheller14:01:12

could just use :init-fn to call what you are now calling at the top level instead of calling it

thheller14:01:46

that ensures that its only called once even if you live-reload that file

hoopes14:01:56

So here's probably a dumb idea. Everytime I run my app, I get warnings from library code. For example:

[:app] Build completed. (1038 files, 8 compiled, 4 warnings, 11.03s)

------ WARNING #1 --------------------------------------------------------------
 File: zprint/focus.cljc:100:47
--------------------------------------------------------------------------------
  97 |         #_(println "range-ssv: start:" start "nwpath:" nwpath)
  98 |         start (skip-whitespace-ssv ssv start)
  99 |         ssv-next (next-ssv ssv start)
 100 |         end (if (and ssv-next (not= start 0)) (dec ssv-next) (dec (count ssv)))]
-----------------------------------------------------^--------------------------
 cljs.core/-, all arguments must be numbers, got [#{nil clj-nil} number] instead
--------------------------------------------------------------------------------
 101 |     #_(println "range-ssv:" [start end])
 102 |     [start end]))
--------------------------------------------------------------------------------

------ WARNING #2 --------------------------------------------------------------
 File: com/rpl/specter/impl.cljc:786:6
--------------------------------------------------------------------------------
 783 |          val))
 784 | 
 785 |      (mk-late-fn-records)
 786 |      (mk-late-fn)))
------------^-------------------------------------------------------------------
 Use of undeclared Var com.rpl.specter.impl/java
--------------------------------------------------------------------------------
 787 | 
 788 | #?(:clj
 789 |    (defn static-fn-code [afn args]
 790 |      `(~afn ~@args))
--------------------------------------------------------------------------------

------ WARNING #3 --------------------------------------------------------------
 File: com/rpl/specter.cljc:1275:19
--------------------------------------------------------------------------------
1272 |           ns (namespace structure)]
1273 |       (cond (keyword? structure) (keyword ns new-name)
1274 |             (symbol? structure) (symbol ns new-name)
1275 |             :else (i/throw-illegal "NAME can only be used on symbols or keywords - " structure)
-------------------------^------------------------------------------------------
 Use of undeclared Var com.rpl.specter/java
--------------------------------------------------------------------------------
1276 |             ))))
1277 | 
1278 | (defnav ^{:doc "Navigates to the namespace portion of the keyword or symbol"}
1279 |   NAMESPACE
--------------------------------------------------------------------------------
There's not much I can do about them except to open an issue on the repo or try to fix them myself. I was wondering if it made sense for some sort of option in shadow-cljs.edn for :ignore-warnings-from-namespaces or :only-show-warnings-from-this-ns-list, so I could more easily see warnings/errors from code I actually control. If there already is something like this that I'm not aware of, my apologies for the large message. Thanks for listening!

Jan K14:01:44

These build reports are really a great feature. I wouldn't have guessed that just requiring cljs.pprint yields almost +100 Kb after optimizations

orestis15:01:26

It seems like you can’t have both an :http-handler fn, and a :proxy-url, right? Because the proxy will take over.

orestis15:01:07

So if I want to do something fancy, I need drop the proxy-url and do the proxy on my own.

orestis15:01:48

Is there some reliable way at runtime (that is, no macros) to get the filename of the file where a function was defined? OK to only work in dev mode.

thheller16:01:45

@hoopes I agree that its unfortunate. I opened issues on the libs I know about and most of them are fixed already. https://github.com/nathanmarz/specter/issues/267

thheller16:01:57

not sure if there was an actual specter release though.

thheller16:01:07

don't know how I feel about ignoring warnings

hoopes16:01:18

yeah, i know it would be a gross hack

hoopes16:01:30

but it would make it a lot easier to see what i screwed up 🙂

thheller16:01:44

would it be enough to make warnings in code from libs just "shorter" so they don't show a source excerpt?

thheller16:01:56

(since you can't do anything about them anyways)

hoopes16:01:56

or even a different color, or whatever - maybe the non-lib errors are brighter, something that i can tell at a glance that it's actually my code, and not something i can (somewhat) safely ignore

thheller16:01:24

@jkr.sw yeah currently cljs.pprint can't be optimized by Closure at all so it gets really huge. https://dev.clojure.org/jira/browse/CLJS-2885

thheller16:01:17

@orestis no that info would only be available via macros

thheller16:01:00

proxy stuff is currently not as flexible as I'd like so yeah it current is one or the other not both

thheller16:01:47

if you need more advanced server setups you should be using your own anyways

thheller16:01:07

the server doesn't need to do anything special for shadow-cljs. just serve the files, nothing else.

thheller16:01:26

@hoopes I'll start by re-ordering the warnings I guess. So warnings from local code come before library code

thheller16:01:35

right now they are in dependency order which isn't useful for that

hoopes16:01:43

this is just my personal preference, so feel free to ignore, but the easiest ones to see are at the bottom (especially when you get the warnings over and over), so i'd prefer "mine" at the end

hoopes16:01:34

but saying i'd prefer to the BDFL of shadow-cljs is a little presumptuous, so do what you think is best 🙂

thheller16:01:49

its tricky. don't want to print too much but also not too little 😛

thheller16:01:14

if only there was a way to not do all this in the terminal and have a richer interface for warnings 😉

hoopes16:01:46

like some sort of page, on a web of some kind

souenzzo18:01:48

After move to lein-tools-deps broke my shadow-cljs build. "release" build still works But when I use (shadow/watch :main) from repl:

[:main] Build failure:
The required namespace "goog" is not available, it was required by "cljs/user.cljs".
I still use :lein {:profile "+dev,+client,+webdev"} (slurp (io/resource "cljs/user.cljs")) ;; => (ns cljs.user)\n (it's a empty namespace, I used it long time ago, now it's empty)

thheller18:01:18

check (io/resource "goog/base.js") look like the closure lib may be missing?

souenzzo18:01:52

Points to

#object[java.net.URL
        0xb705e1b
        "jar:file:/home/souenzzo/.m2/repository/org/clojure/google-closure-library/0.0-20170809-b9c14c6b/google-closure-library-0.0-20170809-b9c14c6b.jar!/goog/base.js"]
When i slurp it, it shows a lot of js

thheller18:01:50

hmm that looks fine

thheller18:01:17

not sure whats happening then

thheller18:01:31

where is cljs/user.cljs from though? shadow-cljs doesn't ship with one?

souenzzo18:01:51

my dev/cljs/user.cljs that is in my classpath

souenzzo18:01:44

The required namespace "goog" is not available, it was required by "cljs/user.cljs". now with (io/resource "cljs/user.cljs") ;;=> nil

souenzzo18:01:27

same after rm -rf .shadow .cljs ...anything-that-i-can-rm I also moved from graalvm into JVM11

thheller18:01:55

I use Java11 so thats fine

thheller18:01:30

check if there are maybe multiple version on the classpath?

thheller18:01:32

(-> (Thread/currentThread)
    (.getContextClassLoader)
    (.getResources "goog/base.js")
    (enumeration-seq))

souenzzo18:01:11

just one "jar:file:/home/souenzzo/.m2/repository/org/clojure/google-closure-library/0.0-20170809-b9c14c6b/google-closure-library-0.0-20170809-b9c14c6b.jar!/goog/base.js"

thheller18:01:14

you did test the resource using the actual shadow-cljs REPL with all the aliases activated right?

thheller18:01:45

what is (io/resource "shadow/build.clj")?

souenzzo18:01:04

"jar:file:/home/souenzzo/.m2/repository/thheller/shadow-cljs/2.7.16/shadow-cljs-2.7.16.jar!/shadow/build.clj"

thheller18:01:32

hmm whats all correct

thheller18:01:42

I have no idea what is up

thheller18:01:03

you did delete .shadow-cljs and restarted shadow-cljs after doing that I assume?

souenzzo09:01:39

After put some jar's on maven Move back to lein without lein-tools-deps. I hope that on the next lein-tools-deps try it not occur

denik20:01:01

quick question: is there a command to watch a build in advanced compilation?

thheller20:01:06

no. that must be triggered manually since they generally take too long for watch

denik20:01:33

got it. loading a js library into the client at runtime. trying to call it errors out, likely due to advanced compilation

denik20:01:47

wondering what the best approach to debug this is

thheller20:01:00

shadow-cljs release your-build --pseudo-names

thheller20:01:05

or shadow-cljs check your-build

thheller20:01:20

check isn't totally reliable but sometimes can help spot externs issues

thheller20:01:36

and always set :compiler-options {:infer-externs :auto}

👍 5
denik20:01:55

what’s the difference between true/auto for infer-externs?

thheller20:01:14

:auto enables it for all your sources

thheller20:01:35

true requires you to (set! *warn-on-infer* true) for every source you want to enable it for

joelsanchez20:01:45

I seem to get this when using checkouts

joelsanchez20:01:47

ZipException too many length or distance symbols java.util.zip.InflaterInputStream.read (InflaterInputStream.java:164)

joelsanchez20:01:18

relevant trace:

[java.util.zip.InflaterInputStream read "InflaterInputStream.java" 164]
               [java.io.FilterInputStream read "FilterInputStream.java" 133]
               [java.io.BufferedInputStream read1 "BufferedInputStream.java" 284]
               [java.io.BufferedInputStream read "BufferedInputStream.java" 345]
               [sun.nio.cs.StreamDecoder readBytes "StreamDecoder.java" 284]
               [sun.nio.cs.StreamDecoder implRead "StreamDecoder.java" 326]
               [sun.nio.cs.StreamDecoder read "StreamDecoder.java" 178]
               [java.io.InputStreamReader read "InputStreamReader.java" 184]
               [java.io.BufferedReader fill "BufferedReader.java" 161]
               [java.io.BufferedReader read1 "BufferedReader.java" 212]
               [java.io.BufferedReader read "BufferedReader.java" 286]
               [java.io.Reader read "Reader.java" 140]
               [$fn__11010 invokeStatic "io.clj" 337]
               [$fn__11010 invoke "io.clj" 334]
               [clojure.lang.MultiFn invoke "MultiFn.java" 238]
               [$copy invokeStatic "io.clj" 406]
               [$copy doInvoke "io.clj" 391]
               [clojure.lang.RestFn invoke "RestFn.java" 425]
               [clojure.core$slurp invokeStatic "core.clj" 6871]
               [clojure.core$slurp doInvoke "core.clj" 6862]
               [clojure.lang.RestFn invoke "RestFn.java" 410]
               [shadow.cljs.devtools.server.npm_deps$get_deps_from_classpath$fn__25207 invoke "npm_deps.clj" 164]
               [clojure.core$map$fn__5587 invoke "core.clj" 2747]
               [clojure.lang.LazySeq sval "LazySeq.java" 40]
               [clojure.lang.LazySeq seq "LazySeq.java" 49]
               [clojure.lang.Cons next "Cons.java" 39]
               [clojure.lang.RT next "RT.java" 706]
               [clojure.core$next__5108 invokeStatic "core.clj" 64]
               [clojure.core.protocols$fn__7852 invokeStatic "protocols.clj" 169]
               [clojure.core.protocols$fn__7852 invoke "protocols.clj" 124]
               [clojure.core.protocols$fn__7807$G__7802__7816 invoke "protocols.clj" 19]
               [clojure.core.protocols$seq_reduce invokeStatic "protocols.clj" 31]
               [clojure.core.protocols$fn__7835 invokeStatic "protocols.clj" 75]
               [clojure.core.protocols$fn__7835 invoke "protocols.clj" 75]
               [clojure.core.protocols$fn__7781$G__7776__7794 invoke "protocols.clj" 13]
               [clojure.core$reduce invokeStatic "core.clj" 6748]
               [clojure.core$into invokeStatic "core.clj" 6815]
               [clojure.core$into invoke "core.clj" 6807]
               [shadow.cljs.devtools.server.npm_deps$get_deps_from_classpath invokeStatic "npm_deps.clj" 168]
               [shadow.cljs.devtools.server.npm_deps$get_deps_from_classpath invoke "npm_deps.clj" 157]
               [shadow.cljs.devtools.server.npm_deps$main invokeStatic "npm_deps.clj" 204]
               [shadow.cljs.devtools.server.npm_deps$main invoke "npm_deps.clj" 199]

joelsanchez20:01:26

im running shadow-cljs as a library, i.e. executing (shadow-cljs.npm-deps/main {} nil) from my program

thheller20:01:36

weird. maybe a broken .jar file on the classpath?

thheller20:01:55

I had this before on linux where is somehow put an empty .jar file on the classpath

thheller20:01:12

the classpath scanner filters those but npm-deps doesn't I guess

thheller20:01:16

@joelsanchez try this in the REPL

thheller20:01:18

(doseq [url (-> (Thread/currentThread)
                (.getContextClassLoader)
                (.getResources "deps.cljs")
                (enumeration-seq))]
  (try
    (slurp url)
    (catch Exception e
      (prn [:failed url e]))))

joelsanchez20:01:05

seems it happens because I use checkouts though

joelsanchez20:01:12

leiningen doing weird stuff

thheller20:01:23

check jar -tvf /home/joel/.m2/repository/ventas-core/ventas-core/0.0.12-SNAPSHOT/ventas-core-0.0.12-SNAPSHOT.jar

thheller20:01:42

the jar file just seems broken

joelsanchez20:01:53

welp my jar is a bit full of crap but it didnt fail

joelsanchez20:01:37

guess if I remove that js stuff from the jar, which shouldn't be included anyway, it will work

thheller20:01:15

thats odd that it doesn't complain though

thheller20:01:50

but yeah that pretty clearly demonstrates why resources/public is a bad idea as a default 😉

thheller20:01:14

> "too many length or distance symbols"

joelsanchez20:01:30

yes, seems a polite way of saying "your jar's full of crap"

thheller20:01:31

guess maybe it really is just too many files 😛

joelsanchez20:01:25

I removed all of that from the jar, executed lein install, jar -tvf now shows much less files, but I get a different error now

joelsanchez20:01:05

I swear this didnt happen before checkouts

joelsanchez20:01:17

but dont worry, it's not critical

thheller21:01:07

no idea. never had issues with checkouts and been using them in my work project for years

thheller21:01:10

especially since it doesn't have an issue reading the checkout

thheller21:01:18

that should be a path not jar

Bravi22:01:09

hello everyone. has anyone used shadow-cljs with om-next?

Bravi22:01:31

I’m getting the following warning

ident? already refers to: cljs.core/ident? being replaced by: om.util/ident?

thheller22:01:25

om-next is pretty much dead AFAICT use fulcro

thheller22:01:35

cljs.core/ident? was added not too long ago. so om.next would need to exclude it to get rid of the warning

Bravi23:01:25

thanks @thheller, I wasn’t aware of that..

Bravi23:01:04

I’ve been with re-frame for a long time, but I wanted to add SSR to my website, so basically to have an isomorphic app

Bravi23:01:32

but it seems to be a pain with re-frame and I was trying to find alternative

thheller23:01:58

#fulcro 🙂

Bravi23:01:33

👍 I’ll have a look into it now 🙂