Fork me on GitHub

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: 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 ?


@cgdeboer what kind of errors do you get?


: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>;</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 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 [ ] ...)


hmm how do you load your scripts then?


maybe they are just loaded async or after the script tag?


😬 here’s a snippet from my root html page.

    <div id="app"></div>
    <script src=""></script>
    <script src="js/compiled/app-hash.js?v={{ fingerprint }}" type="text/javascript"></script>


Is that what you are asking about ?


looks fine, does the script actually load though?


yep. gets a 200 and I can load it independently as well.


do you get any errors before the main error?


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


perhaps bide related.


hmm not sure what that is. $jscomp is stuff injected by the Closure Compiler


do you maybe have an unsupported closure-library version?


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. and it you want to see what a jest/clojurescript setup looks like


I haven’t seen snapshot testing be worthwhile at all, so I don’t do that anymore

👆 1

I’ve used react-testing-library and it was nice for component-implementation tests

💯 2

I see snapshot testing an implementation detail and not really test-first


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

👍 1

Any idea how to do blocking take! from a channel in cljs? In clj you have the <!! but not in cljs


there is no blocking in JS so you can't do it

😓 1