Fork me on GitHub
#clojurescript
<
2019-11-01
>
telperion13:11:32

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 ?

thheller13:11:25

@cgdeboer what kind of errors do you get?

thheller13:11:04

:simple doesn't require externs so if that fails too something else might be going on not related to the actual JS

telperion13:11:17

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.

thheller13:11:00

ok. I assume you are calling something like <script>your.app.main();</script> in your HTML? might be via onload event or so?

thheller13:11:19

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

telperion13:11:34

I have an HTML index with such a line. and in my core.cljs we are (defn ^:export main [ ] ...)

thheller13:11:09

hmm how do you load your scripts then?

thheller13:11:22

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

telperion13:11:15

😬 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>

telperion13:11:04

Is that what you are asking about ?

thheller13:11:26

looks fine, does the script actually load though?

telperion13:11:05

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

thheller13:11:29

do you get any errors before the main error?

telperion13:11:15

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

telperion13:11:28

perhaps bide related.

thheller13:11:05

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

thheller13:11:26

do you maybe have an unsupported closure-library version?

telperion13:11:47

I can take a look. Thanks for the help ! I’ll report back in a bit after looking through any version changes.

thheller13:11:07

you should use the version that ships with clojurescript. don't override it manually

Alex18:11:57

For anyone who heavily used Jest + snapshot testing in JS/React, what are you using now in cljs land?

athomasoriginal14:11:49

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

lilactown20:11:23

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

👆 1
lilactown20:11:51

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

💯 2
mruzekw20:11:20

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

lilactown20:11:16

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
actonDev21:11:48

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

thheller21:11:41

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

😓 1