Fork me on GitHub

hi! how do I require (using require, not :require) some lib that has a leading @ in its name? this works (ns hello-bundler.core (:require ["@urql/core" :as urql])) but how could I use a function to do the same thing?


Do you use self-hosted CLJS?


nope! I'm just following the webpack guide


ok, (require '["@urql/core" :as urql]) seems to work


I thought I had to use a symbol in the function for some reason


Huh. Can you link the guide? I'm just curious.


Ah, alright. Do you use that require in a REPL or in a compiled code?


I want to do both 🙂 REPL for experimentation, then once I get what I want I write it to a .cljs file


And that's exactly what I'm concerned about. No idea about Webpack in particular but AFAIK you can't make require work in a not self-hosted environment outside of REPL. You can still have somewhat dynamic requires with module splitting. And I think you can have proper dynamic requires but with some other tools and not the default require. But I've never done that so can't comment.


oh, no, I want to use require as a function for REPL-driven development, and stick to :requires in ns forms for compilation. seems alright, right?


Ahh, sure!


Defining a macro like

(defmacro hmm [fun]
 `((var ~(symbol fun))))
seems to work as expected in a clojure repl, but not in clojurescript?


ahh thanks!

Michael Jung20:05:35

Hi I’m working on a small project using react native, react navigation, reagent, re-frame, and krell. I’m having trouble getting my code to run with advanced optimizations turned on: one of the functions I call seems to get renamed. I’m using a global atom to get access to the root navigation object of react-navigation (the atom is set by react-navigation using a callback I provided). When I try to use this object, I get problems:

(.dispatch navigation (.replace StackActions "Home"))
navigation is the value from the atom and .dispatch is the problematic method. This is the error message I get:
TypeError: hc($s).Zf is not a function. (In 'hc($s).Zf(_$$_REQUIRE(_dependencyMap[2], "@react-navigation/native").StackActions.replace("Home"))', 'hc($s).Zf' is undefined)
When I manually edit the generated code and replace .Zf with .dispatch, the program works as expected. So my question is: how can I prevent that this function call is being renamed?


Add ^js in front of the definition of navigation.

Michael Jung21:05:55

Let me provide a little more context:

(let [navigation @!navigation]
  (.dispatch navigation (.replace StackActions "Home")))
Should I add ^js like this? (let [^js navigation @!navigation] ?

Michael Jung21:05:17

Seems to have done the trick! Thanks for the quick help @U2FRKM4TW

👍 3