This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-11-01
Channels
- # announcements (7)
- # babashka (41)
- # beginners (117)
- # cider (3)
- # clj-kondo (145)
- # cljdoc (25)
- # cljs-dev (19)
- # clojure (197)
- # clojure-dev (14)
- # clojure-europe (4)
- # clojure-italy (3)
- # clojure-nl (2)
- # clojure-spec (11)
- # clojure-uk (21)
- # clojuredesign-podcast (5)
- # clojurescript (29)
- # code-reviews (4)
- # cursive (87)
- # data-science (11)
- # datomic (29)
- # duct (2)
- # emacs (10)
- # graalvm (1)
- # lumo (13)
- # malli (2)
- # nrepl (5)
- # off-topic (25)
- # onyx (1)
- # pathom (6)
- # reagent (20)
- # reitit (4)
- # rewrite-clj (7)
- # shadow-cljs (114)
- # spacemacs (16)
hey all, long time listener, first time caller. Does anyone have any good tips for debugging compilation. I have an app that that compiles and works will in dev (figwheel), compiles fine and loads properly with :optimizations :whitespace
. However, with :advanced` and :simple
optimizations, the app fails to load. Compilation builds the js asset without errors, but the app fails to load. I get different cryptic console errors with each incantation.
I’ve found some hints here: https://github.com/clojure/clojurescript/wiki/Advanced-Compilation#fixing-advanced-compilation-issues but don’t believe the issue has anything to do with externs, since those are properly defined, and haven’t changed in the project in a while.
Does anyone have any debugging tips or documentation links that have been helpful ?
:simple
doesn't require externs so if that fails too something else might be going on not related to the actual JS
Agreed. I don’t believe externs are to blame.
In all cases, the final error in the console will be something like the below. main
is the name of the function at the root of my project.
(index):31 Uncaught TypeError: Cannot read property 'main' of undefined
at (index):31
(anonymous) @ (index):31
The errors above that in the console vary by the level of optimization I’m using, I can share a sample of those.ok. I assume you are calling something like <script>your.app.main();</script>
in your HTML? might be via onload
event or so?
so in :advanced
compilation namespaces don't exist anymore and are collapsed to a flat structure. so your.app.main()
won't exist anymore. to ensure that it is still accessible you do (defn ^:export main [] ...)
in your namespace
I have an HTML index with such a line. and in my core.cljs
we are (defn ^:export main [ ] ...)
😬 here’s a snippet from my root html page.
html
<body>
<div id="app"></div>
<script src=""></script>
<script src="js/compiled/app-hash.js?v={{ fingerprint }}" type="text/javascript"></script>
<script>
app.core.main();
</script>
</body>
So… those are different in various level of optimizations. I just re-generated the hash and served it up with :simple
and see this before the main
errors:
$jscomp.scope.Router is not a constructor
I can take a look. Thanks for the help ! I’ll report back in a bit after looking through any version changes.
you should use the version that ships with clojurescript. don't override it manually
For anyone who heavily used Jest + snapshot testing in JS/React, what are you using now in cljs land?
You can use jest
with clojurescript if you really want to , but as lilactown said further down, I have come to see that snapshots are not as effective as I felt they were when I was initially introduced to them in Jest. For this reason, i kind of backed off using Jest because as I built a mental model of what Jest is actually doing, much of it can be done with ClojureScript with out of the box tools. https://betweentwoparens.com/clojurescript-test-setup and it you want to see what a jest/clojurescript setup looks like https://github.com/tkjone/demo-clojurescript-jest
I haven’t seen snapshot testing be worthwhile at all, so I don’t do that anymore
I’ve used react-testing-library and it was nice for component-implementation tests
what would normally happen is: - dev would make a change - snapshot tests would break - dev would think, “well I made a change so that makes sense” and tell Jest to update the snapshots - no value was gained