Fork me on GitHub
#shadow-cljs
<
2020-08-20
>
Jack Arrington00:08:10

I've noticed in my shadow-cljs project that when there is an error I don't get any useful line number -- just a bunch of references to browser.cljs. Is this a shadow-cljs limitation or a Clojurescript one, and is there something I can do about it?

Jack Arrington00:08:10

I keep hearing that CLJS has very well-engineered source maps, but it's pretty frustrating to get a basic arity error or something of that nature and have zero idea where it's coming from. I'm hacking on a small project with Clojure right now, but if it grows searching around blindly until I figure out what section of the code an error came from definitely isn't going to be maintainable

Jack Arrington00:08:43

Oh and this is running in watch-mode, if that has anything to do with it

thheller07:08:16

@mail985 you need to be a bit more specific. I have no clue what your problem is. make screenshot or something that shows what you are talking about.

nivekuil12:08:47

I can't seem to get css reloading working. I have a hiccup-generated page loading a css file at "/css/view.css", which on the fs is at resources/public/css/view.css. I'm not using :dev-http so I have {:target :browser ... :devtools {:watch-dir "public" ...} in shadow-cljs.edn. does that look right? maybe I'm missing something in deps.edn? shadow command is server

thheller12:08:43

@kevin842 shjould be :watch-dir "resources/public"

nivekuil12:08:04

hm.. I swear I had already tried that but I just tried it again and it worked. thanks :P

nivekuil12:08:07

maybe I was thrown off by the loading spinner that pops up on the HUD when shadow-cljs.edn is edited, but didn't restart the server

bendlas13:08:35

I have a problem with (:require ["docx4js"]) with :target :react-native, it works, but with :target :browser it throws

[:app] Build failure:
The required JS dependency "/node_modules/docx4js/lib" is not available, it was required by "shadow.js.shim.module$node_modules$docx4js$lib$props.js".

Dependency Trace:
        r8/contree/styled_system.cljs
        node_modules/docx4js/lib/index.js
        node_modules/docx4js/lib/openxml/docx/document.js
        node_modules/docx4js/lib/openxml/document.js
        node_modules/docx4js/lib/document.js
        shadow.js.shim.module.js
Apparently it trips over requiring node_modules/docx4js/lib/$props.js

thheller14:08:54

ah. of course there are npm files that have $ in their name ... why wouldn't there be 😛

thheller14:08:48

due to https://clojure.atlassian.net/browse/CLJS-3235 that is now a special char. guess I'll have to disable that functionality for node_modules ...

bendlas14:08:50

😅 can I quickfix this somehow, short of webpacking that lib?

thheller14:08:18

no clue if you are even on a version with that feature yet. don't have time to look into the issue right now but it'd be my guess that its $

thheller14:08:38

in which case you can only "fix" it by renaming the file and requires thereof

bendlas14:08:51

ok, thanks!

lilactown16:08:39

I have a .cljc file which uses a namespaced keyword in a :clj branch. When trying to evaluate that in a CLJS REPL, it barfs:

(cljs.core/load-file "/Users/lilactown/Code/amperity/app/service/web/web-ui/src/amperity/web/mx_segment/core.cljs")
------ ERROR -------------------------------------------------------------------
 File: /Users/lilactown/Code/amperity/app/service/segment/segment-core/src/clj/amperity/mx_segment/folder.cljc:52:20
--------------------------------------------------------------------------------
  49 |    (do
  50 |      (pc/defresolver list-resolver
  51 |        [{:keys [tree] :as env} _input]
  52 |        {::pc/output [{::all config-keys}]}
--------------------------^-----------------------------------------------------
amperity/mx_segment/folder.cljc [line 52, col 20] Invalid keyword: ::pc/output.

--------------------------------------------------------------------------------
  53 |        (d/chain
  54 |          (list tree)
  55 |          (fn [seg-list]
  56 |            {::all seg-list})))
--------------------------------------------------------------------------------

lilactown16:08:41

the namespace only exists in the :clj branch as well, so if the reader is trying to interpret it it makes sense why it would barf. I would just expect it skip it since it’s in a reader conditional

lilactown16:08:53

full offending code:

#?(:clj
   (do
     (pc/defresolver list-resolver
       [{:keys [tree] :as env} _input]
       {::pc/output [{::all config-keys}]}
       (d/chain
         (list tree)
         (fn [seg-list]
           {::all seg-list})))


     (pc/defresolver get-resolver
       [{:keys [tree] :as env} {:keys [::id] :as input}]
       {::pc/input #{::id}
        ::pc/output [{::node config-keys}]}
       (d/chain
         (get tree id)
         (fn [node]
           {::node node})))))

thheller16:08:31

@lilactown either branch of the code must still be readable and as such must have that alias. not anything shadow-cljs can do anything about.

thheller16:08:15

you can fake whatever alias you want but it must exist regardless

thheller16:08:57

would need to be fixed in clojure and tools.reader if you want to take that on 😉

lilactown16:08:57

alright 😄 thanks

lilactown16:08:34

it’s pathom, so it is cljc. I’d rather not include all of pathom in my bundle if not necessary tho

lilactown16:08:51

do you think pathom would get :knife: if I require it but never refer it?

thheller16:08:09

like I said .. only the alias needs to exist. doesn't matter what it points to (:require [clojure.string :as pc])

lilactown16:08:14

(I can check this myself just thought I would ask if you know off hand)

lilactown16:08:28

yeah that’s true!

lilactown16:08:42

another question: I recently updated to 2.10.21. I’m now receiving an error on release:

--- amperity/web/stitch/report_v2/viz.js:1
Cannot import Closure files by path. Use either import goog:namespace or goog.require(namespace)

lilactown16:08:07

this file is an es module - I remember rewriting it from a goog module to es syntax

lilactown16:08:37

did the ES module require-by-path get removed?

lilactown16:08:33

or is there some way that I need to signal that it is in fact an es module, and not a goog module? (other than use import and export, which it does)

thheller16:08:15

I haven't looked into this yet but there have been other reports

bendlas16:08:22

Not sure if that will answer your question, but I'm adding node modules in a separate source folder and make them available as package.json dependencies: "local-package": "file:./local-package-src"

thheller16:08:33

not nothing should have changed in that regard. but it bumped closure which tends to change stuff ...

thheller16:08:38

@bendlas I think this particular aliasing problem warrants a new issue. given that the code is immediately discarded anyways it shouldn't attempt to resolve it.

bendlas16:08:49

You mean about the missing ::alias/ns behind a read-cond? Yeah, that would be good to get fixed in the reader ...

thheller16:08:34

I never tried but symbols may have the same problem. but yes on read-cond branches that aren't active a missing alias shouldn't break the code.

thheller16:08:02

is also resolved by the reader. probably breaks too.

bendlas16:08:27

Unfortunately, clojure.tools.reader/*alias-map* seems to be the only facility for that. I guess that could be hacked, by implementing ILookup, but there would be many open questions then, about how to proceed after read-cond has been resolved ...

thheller16:08:21

would really need to be fixed in clojure first imho

thheller16:08:40

no point in adding stuff to tools.reader that clojure doesn't support

bendlas16:08:33

true. clojure doesn't have :read-cond :preserve, does it?

thheller16:08:01

no clue. whats that?

bendlas16:08:36

that's for retaining read-cond branches

thheller16:08:55

ah. and there goes all hope for getting this "fixed" I guess 😛

bendlas16:08:06

so then, boxing ::alias/kw would be part of the deal ..

lilactown16:08:17

is there a known good version I can downgrade to w.r.t. es module issue, that’s better than going back to what I was on (2.8.61 😅 )

thheller16:08:42

since I don't know what the issue is I cannot possibly answer that

lilactown16:08:07

I’ve narrowed it down to being introduced in 2.9.7

thheller17:08:50

thanks. I'll see if I can figure it out.

thheller17:08:41

@bendlas your issue should be fixed in 2.10.22.

❤️ 3
bendlas09:08:42

Seems lile that lib does more freaky stuff, that we're tripping over: • require("f" + "s") at https://github.com/lalalic/docx4js/blob/84ae60e0395e3cef066055d11392732b65c76d90/lib/document.js#L206

[:app] Compiling ...
[2020-08-21 11:47:11.520 - INFO] :shadow.build.npm/js-invalid-requires - {:resource-name "node_modules/docx4js/lib/document.js", :requires [{:line 206, :column 14}]}

bendlas09:08:01

Then there is

[:app] Build failure:
The required JS dependency "entities/maps/entities.json" is not available, it was required by "node_modules/htmlparser2/lib/Tokenizer.js".

Dependency Trace:
        r8/contree/styled_system.cljs
        node_modules/docx4js/lib/index.js
        node_modules/docx4js/lib/openxml/docx/document.js
        node_modules/docx4js/lib/openxml/document.js
        node_modules/docx4js/lib/document.js
        node_modules/docx4js/lib/$props.js
        node_modules/cheerio/index.js
        node_modules/cheerio/lib/cheerio.js
        node_modules/cheerio/lib/parse.js
        node_modules/htmlparser2/lib/index.js
        node_modules/htmlparser2/lib/Parser.js
        node_modules/htmlparser2/lib/Tokenizer.js
, where it refers to node_modules/entities/lib/maps/entities.json. Not sure, if that's related to the other error, somehow ..

thheller10:08:04

thats probably a version conflict. like expecting an older/newer version of entities

bendlas10:08:07

strange .. again, in :target :react-native it works ...

thheller10:08:10

yeah dynamic requires like the faked require("fs") are just to hide them from packagers. pretty stupid but I guess thats common in the JS world

bendlas10:08:25

thought so ..

thheller10:08:37

:target :react-native does no bundling whatsoever by shadow-cljs. its all done by react-native metro

thheller10:08:59

and they are happy to include 2 versions of the same library. so you just get entities twice

bendlas10:08:10

I mean, I'm happy to browserify/webpack this stuff, just wanting to let you know ...

thheller10:08:12

shadow-cljs does not do that and will never do that.

bendlas10:08:26

oh right, it's there 3 times

entities
htmlparser2/node_modules/entities
cheerio/node_modules/entities

thheller10:08:38

fun times .. then you get 3 versions of it in react-native. totally doesn't bloat your final bundle at all 😉

bendlas10:08:38

... as opposed to maven's randomly changing your version. it's really pest vs cholera 😞

thheller10:08:00

you can set :js-options {:resolve {"entities/maps/entities.json" {:target :npm :require "entities/lib/maps/entities.json"}}} I think. never actually tried using it to override direct references but it should work

bendlas10:08:15

what should be the key to the inner map?

thheller10:08:15

in your build config that is

bendlas10:08:52

thanks, I'll try!

bendlas10:08:34

Ha! Neat! That actually worked. 🙂

bendlas10:08:54

Had to also do it for 2 other files, but that's really good to know

bendlas10:08:47

the dynamic require is just a warning, and I'm not hitting the require("fs") path in the browser anyway

bendlas10:08:57

Good times. Thanks!

thheller10:08:43

yeah thats why requires like that are just a warning and not an error 😛

royalaid17:08:46

@thheller at my new job we are doing a lot of serverless stuff so I end up having to jump into cloudwatch and copy and pasting edn a bunch. I am wondering if there is a way I can leverage tap> from within the AWS lambdas and point it at a kind of IRC Bouncer/inbox style thing and then pick the tap>ed values up on my local machine using shadow inspect

thheller17:08:44

in theory yes. the code isn't written in practice though 😉

thheller17:08:29

hmm don't the lambdas die after they have done their work?

thheller17:08:11

tap> never actually transfers the full value so that would be a problem

thheller17:08:59

you could automate the EDN copying. if you get it to your shadow-cljs instance you can just tap> it from CLJ

royalaid18:08:08

The lambda's do die after

royalaid18:08:18

I was under the impression that it actually sent a message

royalaid18:08:28

But I guess the bouncer thing could handle that

royalaid18:08:58

Gonna have to poke around with tap I guess

jeff tang20:08:34

After I moved to an Electron app, I began getting this async-dispatch-N error when I shadow-cljs watch renderer . It happens non-deterministically, and usually mentions @material-ui/icons . The build is `

:renderer {:target :browser
                     :output-dir "resources/public/js/compiled"
                     :asset-path "js/compiled"

                     :modules {:renderer {:init-fn athens.core/init}}

                     :compiler-options {:closure-warnings {:global-this :off}
                                        :closure-defines {re-frame.trace.trace-enabled? true}}

                     :devtools {:preloads [devtools.preload
                                           day8.re-frame.trace.preload]}}

thheller20:08:20

@tangj1122 only guess I have is that you maybe have a bad core.async version

thheller20:08:30

make sure it matches the version shadow-cljs needs

thheller20:08:51

check other possibly dependency conflicts while you are at it 😛

thheller20:08:15

but could be a simple overload. @material-ui/icons adds thousands of files to your build. I fixed something to that extent in some version. can't remember which.

jeff tang20:08:30

hmm cljs.core.async is not a dependency in this project

thheller20:08:03

check lein deps :tree for conflicts

thheller20:08:37

or maybe just try upgrading. could just be the overload issue I fixed not too long ago

jeff tang20:08:39

ok, trying to upgrade from 2.8.110 to 2.10.22

jeff tang20:08:52

(no conflicts in deps tree)

jeff tang20:08:50

I don't seem to be getting the error anymore, after running it 5 times. The probability is in my favor. Thanks @thheller ❤️

👍 3