Fork me on GitHub
#clojurescript
<
2022-10-21
>
jlfischer02:10:45

I’m prototyping out a ClojureScript project that ideally will target iOS 9.3.6 at a minimum, so I’ve configured the ClojureScript compiler to output es5. When I build with optimizations (e.g. shadow-cljs’s release builds), I don’t see any issues but when I build without optimizations (shadow-cljs’s dev builds) I see this error in the console:

review.js:1467 TypeError: $jscomp.inherits is not a function
    at eval (es6.js:144:32)
    at goog.loadModule (review.js:301:27)
    at eval (es6.js:11:1)
    at eval (<anonymous>)
    at goog.globalEval (review.js:500:12)
    at env.evalLoad (review.js:1575:12)
    at review.js:1680:12
reportError @ review.js:1467
review.js:1469 The above error occurred when loading "goog.iter.es6.js". Any additional errors after that one may be the result of that failure. In general your code cannot be trusted to execute properly after such a failure. Make sure to fix the first one before looking at others.
At the moment everything appears to work fine, but it’s just a barebones project. Anyone know if this will be end up being a problem? I’m guessing the solution is to use an older cljs with the corresponding older Google Closure, but I thought I’d ask.

jlfischer02:10:31

I think I’ll be fine as long as I avoid ES6 iterators: that code is likely getting stripped out in release builds, which is why I don’t see an error there.

jlfischer03:10:58

Actually, I should note: I see that error in the JavaScript console on the most recent Chrome version, so it’s not an older browser thing. Hrm.

thheller05:10:37

which shadow-cljs version? older versions forgot to include polyfills for dev builds, newer versions should be fine

thheller05:10:15

note that polyfills are only included one on load, so if you add code via the REPL that requires them it won't work. needs a full page refresh in those cases

jlfischer15:10:07

2.16.2, looks like I’m a bit behind. I’ll give that a try, thanks!

DrLjótsson13:10:59

I have an .edn file with data that I would like to be available in a var in compiled cljs code. Is that possible? Maybe a macro that reads the contents of the file and then `(goog-define my_var data-from-file)` - but that seems cumbersome. Won't work,`goog-define` only accepts strings, numbers and booleans. Any ideas, pointers?

p-himik13:10:32

If the amount of data is not huge, yes, you can use a macro. Thomas Heller (thheller here) has written a post about it on Clojureverse but it has also been discussed a number of times here. And you can write such a macro yourself - it's rather trivial. As an alternative, you can make that data a part of your HTML in a <script> with custom type - makes sense for somewhat larger payload because then you can use transit with compression. Finally, for client-server apps you can issue an AJAX request to fetch that data at run time.

DrLjótsson13:10:00

I can't get it to read from my resources directory though. I'm not too skilled at Java's classpath so not sure how to get it working.

p-himik13:10:06

Ah, nice, I was about to explain it. :)

DrLjótsson13:10:30

I'll ask next time I'm confused 🙂

👍 1