cljsrn

Bingen Galartza Iparragirre 2022-09-20T07:01:01.660519Z

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

Richie 2023-07-27T13:52:11.512859Z

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.

Richie 2023-07-27T13:55:24.866629Z

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.

dsp 2022-09-20T11:16:19.196129Z

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

Bingen Galartza Iparragirre 2022-09-20T12:05:33.056879Z

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 🙂

dsp 2022-09-20T12:05:48.093599Z

ah damn. sorry

dsp 2022-09-20T12:08:28.251849Z

how about (def AsyncStorage (.-default (js/require "@react-native-async-storage/async-storage")))

dsp 2022-09-20T12:08:41.897229Z

I freely admit to not having real world experience with krell and this sort of thing though

Bingen Galartza Iparragirre 2022-09-20T12:10:12.433269Z

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

Bingen Galartza Iparragirre 2022-09-20T12:10:50.705139Z

The problem is that (js/require "@react-native-async-storage/async-storage")` already returns nil, so getting .-default over nil fails too

dsp 2022-09-20T12:11:54.033939Z

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

dsp 2022-09-20T12:12:03.462279Z

other libs are js/require'd fine?

dsp 2022-09-20T12:13:07.601289Z

(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

Bingen Galartza Iparragirre 2022-09-20T12:14:06.746689Z

Yep, it works for other libraries like. For example with @aws-sdk/client-s3

dsp 2022-09-20T12:14:12.130079Z

does (js/require "absolute-nonsense") also return nil if it's nonexistent?

dsp 2022-09-20T12:15:02.666849Z

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

Bingen Galartza Iparragirre 2022-09-20T12:16:14.268369Z

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

dsp 2022-09-20T12:16:52.038389Z

then that's a start, since it means that at least it is doing something, just not what we expect 🙂

Bingen Galartza Iparragirre 2022-09-20T12:18:17.913489Z

yep, good point!

Bingen Galartza Iparragirre 2022-09-20T12:29:48.062809Z

I was wrong, no exception when require doesn't exist 🤔

dsp 2022-09-20T12:30:22.295839Z

npm install or similar done, i.e. the lib is definitely in your node_modules?

Bingen Galartza Iparragirre 2022-09-20T12:30:26.974439Z

Requring @aws-sdk/client-s3 or react-native returns a JS object

Bingen Galartza Iparragirre 2022-09-20T12:31:08.874089Z

yeap, it is in package.json

Bingen Galartza Iparragirre 2022-09-20T12:31:25.858979Z

Just like other npm libraries we are using

dsp 2022-09-20T12:31:34.023739Z

package.json is just the definition of the packages to install though right?

dsp 2022-09-20T12:32:22.117189Z

find node_modules -type d | grep react-native-async-storage$

dsp 2022-09-20T12:32:35.436659Z

I get: node_modules/@react-native-async-storage

Bingen Galartza Iparragirre 2022-09-20T12:33:18.324869Z

Yep, same here

dsp 2022-09-20T12:33:52.428889Z

❯ find node_modules | grep react-native-async-storage | wc -l
132
I imagine it's not a case of anything missing

dsp 2022-09-20T12:34:23.058019Z

I 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 🙂

Bingen Galartza Iparragirre 2022-09-20T12:35:21.772649Z

Returns 258 for me

Bingen Galartza Iparragirre 2022-09-20T12:35:33.997159Z

I'm also a newbie regarding Krell 😅

Bingen Galartza Iparragirre 2022-09-20T12:35:46.555489Z

But thanks for trying anyway. Much appreciated!

dsp 2022-09-20T12:35:55.901319Z

my deps: "@react-native-async-storage/async-storage": "~1.17.3",

Bingen Galartza Iparragirre 2022-09-20T12:36:25.144099Z

I have ^1.17.10

dsp 2022-09-20T12:36:41.497629Z

likely work similarly. I'll bump mine and check

Bingen Galartza Iparragirre 2022-09-20T12:42:01.309699Z

ok, nice

dsp 2022-09-20T12:47:14.321309Z

❯ grep -m 1 version node_modules/@react-native-async-storage/async-storage/package.json
  "version": "1.17.10",

dsp 2022-09-20T12:48:41.857809Z

LOG getting keys: [:account-email] so yes, it appears to work okay, so I don't think it is a version issue.

👍 1
Bingen Galartza Iparragirre 2022-09-20T13:10:36.647279Z

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

🙌 1
Bingen Galartza Iparragirre 2022-09-20T13:10:58.414319Z

Once I add it to a namespace and rebuild the project it also works from the REPL

Richie 2023-10-13T14:32:11.148189Z

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

👏 1
Roman Liutikov 2022-09-20T20:56:27.164339Z

In case someone is looking for writing re-animated worklets in cljs 👉 https://github.com/roman01la/cljs-worklet

👍 2
👏 6
raspasov 2023-05-12T17:19:44.696229Z

This is amazing.

joshmiller 2022-09-20T21:31:34.915219Z

Nice work!

🙏 1
Daniel Gerson 2023-05-11T10:48:39.774479Z

@roman01la Life saver! 🙏

💥 1