This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-09-27
Channels
- # announcements (1)
- # aws (8)
- # babashka (77)
- # babashka-sci-dev (8)
- # beginners (29)
- # biff (2)
- # calva (13)
- # cljs-dev (1)
- # clojure (42)
- # clojure-europe (205)
- # clojure-nl (1)
- # clojure-norway (5)
- # clojure-uk (4)
- # clojurescript (58)
- # conjure (9)
- # data-science (7)
- # datalevin (19)
- # datomic (3)
- # emacs (7)
- # fulcro (15)
- # gratitude (8)
- # lsp (52)
- # meander (3)
- # membrane (92)
- # off-topic (12)
- # re-frame (16)
- # reagent (4)
- # reitit (15)
- # releases (1)
- # sci (30)
- # shadow-cljs (34)
- # tools-deps (5)
- # xtdb (17)
I'm trying to require a lib (xterm.js) that the Clojure compiler refuses to compile (similar to https://github.com/thheller/shadow-cljs/issues/971). If I include the built library as a script directly in my HTML, everything works. However, I'd like to load the library dynamically, and am using require.js for this. The library loads fine and require.js gives me a handle to it, but the CLJS compiler is giving me "Cannot infer target type in expression" when I try to call functions in the library (e.g. (js/require ["xterm"] #(.Terminal %))
). What's the recommended/proper way to solve this? Do I need to manually write an externs file?
@wombawomba please include the actual error you get, otherwise I can't comment at all
also no clue what (js/require ["xterm"] #(.Terminal %))
this is supposed to be? ah I guess require.js
yeah that's require.js
the literal error for the snippet I posted is Cannot infer target type in expression (. p1__240117# Terminal)
the above is an externs inference warning. see https://shadow-cljs.github.io/docs/UsersGuide.html#infer-externs
yeah, on it
putting [xterm :refer [Terminal]]
in my (:require ...)
statement gives the following error (for xterm 5.0.0, which is the latest version):
Closure compilation failed with 1 errors
--- node_modules/xterm/lib/xterm.js:2
Illegal variable reference before declaration: e
Perhaps this is because it's picking up the built and minified xterm.js at xterm/lib/xterm.js
, and I should be requiring something else?
right, okay
so anyway, do you have a recommended course of action here?
Is there a way to force cljs to make the .Terminal
call verbatim without bothering with externs, or do I need to add an externs file?
yeah that did the trick
thanks!
wait, crap, that gives me an error at runtime: Class constructors cannot be invoked without 'new'
How do I combine new
with this type hint/tag? (new Terminal. ^js %)
gives me Use of undeclared Var my.ns/Terminal
alright, I have no idea why, but doing (let [ctor (.-Terminal ^js %)] (new ctor))
works 😅
yeah, I actually already moved the constructor call out of the require.js callback
right yeah, but what threw me off is that (new (.-Terminal ^js %))
also doesn't work
for whatever reason I had to bring the (.- Terminal ^js %)
call out into a binding
is there a way of printing the dependency tree for shadow-cljs.edn dependencies? (like with clj -Stree)
only if you use shadow-cljs.edn to manage deps though. if you use lein or deps.edn use those commands
oh nice, thanks @U05224H0W!