Hello. I'm trying to use the @react-native-async-storage/async-storage library in a Krell CLJS project, but I'm having trouble to require it. Running (js/require "@react-native-async-storage/async-storage") returns nil. The dependency is declared in the package.json file. Any idea how I could do it? thanks
I'm not able to require AsyncStorage in my ns e.g. (ns my-ns (:require ["@react-native-async-storage/async-storage" :refer [AsyncStorage]])) but I can use (def AsyncStorage (.-default (js/require "@react-native-async-storage/async-storage"))). Thanks for that!
I'm using this starter project for react native with expo https://github.com/PEZ/rn-rf-shadow.
I just wanted to say thank you.
Also, why can't I :require it? I have not seen js/require until just now.
Oh. :require ["@react-native-async-storage/async-storage" :default async-storage]
I see that in what you linked to. It just doesn't show up in the slack preview. Ok, I guess that's the "correct" way to do it. Interesting. I've also never seen that before.
I admit it does not strictly meet your requirements, but I only last night was doing a similar thing (just with a shadow-cljs + re-frame project). maybe it would be helpful information anyway? I leaned on status-react (MPL 2.0) to figure out how the stuff works. see: https://github.com/status-im/status-mobile/blob/develop/src/status_im/async_storage/core.cljs
If I'm not mistaken the require there is shadow-cljs specific. I tested it just in case, but didn't work. But thanks anyway 🙂
ah damn. sorry
how about (def AsyncStorage (.-default (js/require "@react-native-async-storage/async-storage")))
I freely admit to not having real world experience with krell and this sort of thing though
For some more context. At the moment we are using the react-native builtint AsyncStorage. And that one does work: (g/getValueByKeys (js/require "react-native") "AsyncStorage") But it's deprecated, so that's why we want to switch to the new lib
The problem is that (js/require "@react-native-async-storage/async-storage")` already returns nil, so getting .-default over nil fails too
yeah, I wasn't sure if there was some magic going on in the background that I was unaware about, am still new to the cljs runtime
other libs are js/require'd fine?
(I mean, you talk about "react-native", but that naming convention is different, and I don't know if it makes any difference). but also don't know what js/require returns on success
Yep, it works for other libraries like. For example with @aws-sdk/client-s3
does (js/require "absolute-nonsense") also return nil if it's nonexistent?
just mentally trying to narrow down whether it's actually doing something (and being not useful) or whether this is expected behaviour if it can't find what it's looking for
Need to restart the environment, will test and tell you in a second. I think it actually returns an exception if you require something that doesnt' exist
then that's a start, since it means that at least it is doing something, just not what we expect 🙂
yep, good point!
I was wrong, no exception when require doesn't exist 🤔
npm install or similar done, i.e. the lib is definitely in your node_modules?
Requring @aws-sdk/client-s3 or react-native returns a JS object
yeap, it is in package.json
Just like other npm libraries we are using
package.json is just the definition of the packages to install though right?
find node_modules -type d | grep react-native-async-storage$
I get: node_modules/@react-native-async-storage
Yep, same here
❯ find node_modules | grep react-native-async-storage | wc -l
132
I imagine it's not a case of anything missingI am at the limits of my knowledge here, not sure what else to suggest. I am sure there are people here with some hands-on krell experience and more js ecosystem knowledge than me. I'm strictly an amateur 🙂
Returns 258 for me
I'm also a newbie regarding Krell 😅
But thanks for trying anyway. Much appreciated!
my deps:
"@react-native-async-storage/async-storage": "~1.17.3",
I have ^1.17.10
likely work similarly. I'll bump mine and check
ok, nice
❯ grep -m 1 version node_modules/@react-native-async-storage/async-storage/package.json
"version": "1.17.10",LOG getting keys: [:account-email] so yes, it appears to work okay, so I don't think it is a version issue.
Found the problem. In order for Krell to load the library the require has to be placed in some namespace. So at build time Krell can find and include the external library. I was doing it directly from the REPL, so that's why it didn't work
Once I add it to a namespace and rebuild the project it also works from the REPL
This came up again for me. This time it was (require '["@expo/vector-icons/Ionicons" :default Ionicons]). I just want to bump this for awareness. https://clojurians.slack.com/archives/C0E1SN0NM/p1689726409781639 and https://clojurians.slack.com/archives/C0E1SN0NM/p1689746339479029
In case someone is looking for writing re-animated worklets in cljs 👉 https://github.com/roman01la/cljs-worklet
This is amazing.
Nice work!