I am having problems with Krell and the Hermes engine. I need to use the engine because I depend on react-native-reanimated in my app. However, the :language-out :es5 setting seems to have no effect. Thanks in advance for any suggestions, answers.
Turning off the Hermes engine results in a run-time exception (red screen of death).
I resolved my :language-out :es5 problem with Hermes. It was due to a mismatch between the Clojurescript compiler and Krell. I restored my deps.edn to use Krell only and everything works now.
However, when I compile, I get the following errors:
ERROR Could not evaluate [SyntaxError: 16:150:';' expected]
ERROR Could not evaluate [TypeError: Cannot read property 'getLogger' of undefined]
This is because Krell or Clojurescript inserts exclamation points in the var name. I verified this by replacing these with _ characters and it solves the problem. Also, this bug breaks REPL output, since pprint does not work.
Please help me solve this problem. Thanks in advance.@hadilsabbagh18 I think you also need to add this: https://clojurians.slack.com/archives/C0E1SN0NM/p1682317131878809?thread_ts=1682298271.486439&cid=C0E1SN0NM
I personally just don’t use Hermes but it comes up in here a lot
Thanks @joshmiller I really appreciate it.
If that works, could you post your working build.edn here or somewhere else? We just have scattered references to settings in the channel and elsewhere.
Yes, I will.
That didn’t work. I think that is a shadow-cls setting. I am using Krell.
Argh, yeah, looking back farther I see that now
I am going to try switching to jsc. I am blocked right now.
I have just stuck with JSC, but I’m not using reanimated
Good to know.
I wonder if you could get away with using advanced optimizations since you wouldn’t get all the special characters in the variable names
does that work with the REPL?
No, not at all.
Just curious if it would work.
ok.
Let me see if I can get jsc to work, then I may try that later.
You could also try :es5-strict as your output
Tried that, didn’t work.
When I use JSC, I get the red screen of death saying “Can’t find require”
https://github.com/google/closure-compiler/wiki/Flags-and-Options
I wonder if there’s a) a compiler option that will let you remap $ to something Hermes doesn’t choke on and b) if that’s exposed to the Clojurescript compiler tool
--rename_variable_prefix VAL
Specifies a prefix that will be prepended to all variables.It is the ! character and it is probably done before the closure compiler, because the repo path is appended to the var name with the !
Can you paste a snippet of what that emitted code looks like?
I will tomorrow. For now, I am trying to get JSC to work.
Cool 👍
I replicated this in my own project just now, found a couple things:
1) The only place it happens is goog/log/log.js, and that’s also the only place with the file location ..._m2$repository$google_closure_library$ bits at all
2) Someone ran into this with figwheel back in 2021, same place, but without any kind of resolution: https://clojurians-log.clojureverse.org/clojurescript/2021-07-29
Thank you for your findings, @joshmiller. I am having difficulty with JSC at the moment.
I will look into encoded JVM resources though
Would you happend to know how to properly upgrade the Clojurescript dependency in deps.edn?
for Krell?
You can just specify a Clojurescript version in deps.edn. I tried downgrading to the one described as working in that 2021 conversation, but it broke too many things in my project. I tried upgrading to the latest and it didn’t fix anything.
Thanks @joshmiller. My JSC is stuck. I am thinking of using RN instead of Expo
The problem seems to be when it rewrites a class Foo into an es5-compatible function, and it expands the file location but when it’s in a jar it doesn’t know that that file is going to have a ! in the resource path
I think log.js is just the only Closure library with classes in it that is likely to be called from ClojureScript
so should i just write a script to fix it?
I think you could do that as a quick hack, just text replace !$ with _$ in that one file
good idea!
I’m trying to see if there’s a place to actually fix it in case another file gets pulled in as well
@hadilsabbagh18 I posted about the problem in #clojurescript https://clojurians.slack.com/archives/C03S1L9DN/p1722966979115689
I think it’s a Closure bug? Probably because they’re not expecting JAR file sources.
Why only this file, though?
I believe it’s because it’s the only file that uses ES6 classes that’s in a JAR that is required by the CLJS in a normal RN project.
Ah
Ok, so I have a hack that works for me:
• Create a file scripts/fixClosure.sh with these contents:
#!/bin/sh
find ./target/goog -type f -name "*.js" -exec sed -i '' 's/\!\$/_$/g' {} +
• Update my start in package.json to be "sh ./scripts/fixClosure.sh && react-native start"
This requires that you wait for Clojure to finish compiling and be ready for a repl before doing yarn start or npx start, but since those files aren’t getting re-compiled during dev, it doesn’t need to run again.