Getting `core.cljs:3868 Uncaught TypeError: Illegal invocation` in Electron Clojurescript project
Closed this issue ยท 6 comments
Description
Adding Ghostwheel to Electron Clojurescript project produces error in browser console that prevents Ghostwheel logging.
With this project.clj
config (only related parts):
:dependencies [[org.clojure/clojure "1.9.0"]
[org.clojure/clojurescript "1.10.339"]
[gnl/ghostwheel.tracer "0.3.5"]
[gnl/ghostwheel "0.3.5"]
[cljsjs/nodejs-externs "1.0.4-1"]
[reagent "0.8.1"]]
:plugins [[lein-cljsbuild "1.1.7"]]
:min-lein-version "2.5.3"
:cljsbuild {:builds {:app {:source-paths ["src/cljs"]
:compiler {:output-to "app/js/p/app.js"
:output-dir "app/js/p/out"
:asset-path "js/p/out"
:optimizations :none
:pretty-print true
:cache-analysis true}}}}
:clean-targets ^{:protect false} [:target-path "out" "app/js/p"]
:figwheel {:css-dirs ["app/css"]}
:repl-options {:nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]}
:profiles {:dev {:cljsbuild {:builds {:app {:source-paths ["env/dev/cljs"]
:compiler {:source-map true
:main "skarbnik.dev"
:verbose true
:preloads [devtools.preload]
:external-config {:ghostwheel {}}}
:figwheel {:on-jsload "skarbnik.core/mount-root"}}}}
:source-paths ["env/dev/cljs"]
:dependencies [[figwheel-sidecar "0.5.17"]
[binaryage/devtools "0.9.10"]
[cider/piggieback "0.3.1"]]
:plugins [[lein-ancient "0.6.8"]
[lein-kibit "0.1.2"]
[lein-cljfmt "0.4.1"]
[lein-figwheel "0.5.17"]]}
Reproduction guide ๐ชฒ
- Creating project with
lein new electron <name>
. - Bumping up versions of Clojure and dependencies as per
project.clj
above. - Do all steps to run Cljs-electron app as in electron template instructions.
- Add Ghostwheel to
core.cljs
and some example function such as:
(>defn addition
[a b]
[pos-int? pos-int? => int? | #(> % a) #(> % b)]
(- a b))
- Add
(g/check)
at the bottom of thecore.cljs
. - run
lein figwheel
and in another terminalgrunt launch
, that should start app.
Expected behaviour: โค๏ธ ๐
Ghostwheel's report.
Can you try [gnl/ghostwheel "0.3.6-SNAPSHOT"]
and report back if that fixes it?
Looks like there might be an issue with doing a simple (apply js/console.log ...)
โ it works just fine on the current Chrome and Node, but it's possible Electron is using an older version of Chromium.
http://clojurescriptmadeeasy.com/blog/how-to-apply-with-the-console-api.html
Thank you for the hint to the right direction, I have updated Electron and that fixed the issue. However, I see a warning that ::g/check
disabled for namespace where I invoke (g/check)
. Not big of a deal though. So, this issue can be closed, I suppose. Thank you for your great work!
Just to be clear, after the Electron upgrade, it worked fine with which version โ 0.3.5 or 0.3.6-SNAPSHOT?
As for the (g/check)
warning โ this should only happen if ::g/check
is disabled either globally or for the namespace โ can you confirm that it goes away when you turn on ::g/check
on any level?
It works with both versions of Ghostwheel when ClojureScript app uses Electron v3.0.10..
I have ::g/check
enabled in the namespace where my tested function is placed, so as per the docs:
#:ghostwheel.core{:check true
:num-tests 10}
I didn't disable it anywhere. You can see my project.clj
where Ghostwheel is referenced in :external-config
, that's the only other place where I do anything with config, but that's how it is supposed to work, I assume.
One thing I tried is to add {::g/check true}
to the tested function itself, it seems to be removing that warning. This works:
(>defn ranged-rand
"I was lifted straight from the clojure.spec guide"
{::g/check true}
[start end]
[int? int? | #(< start end)
=> int? | #(>= % start) #(< % end)]
(+ start (long (rand (- end start)))))
I cannot reproduce the warning issue โ it's only displayed here when ::g/check
isn't enabled (it's off by default), and it goes away when it's enabled on any level. I suspect that it may be related to namespace metadata not being reloaded correctly on recompile with some hot-reload workflows:
https://dev.clojure.org/jira/browse/CLJS-1926
Can you try cleaning your whole build, restarting everything with :check true
in the namespace as you have it now, and opening a new issue if the problem's still there?
And I'd generally recommend setting the config on the highest level possible, so if you'll be using Ghostwheel throughout your project, probably best to put the bulk of your config in the ghostwheel.edn
config file or under :external-config
in the compiler options.
ghostwheel.edn
is probably the better option as it works nicely with hot-reload workflows.