Fork me on GitHub
#cljsrn
<
2019-09-28
>
Maksym15:09:17

When I run (js/require "") in repl terminal I see next error:

repl/invoke error, [ReferenceError: Can't find variable: require]
- node_modules\react-native\Libraries\YellowBox\YellowBox.js:59:8 in error
Can you explain why it's happening and how ti fix it?

thheller16:09:39

require is a compile-time construct in react-native. it is not a function you can call at runtime, so it cannot be used from the REPL

Maksym16:09:13

Is there other way to require file?

thheller16:09:50

just don't do it at the REPL. it works in regularly compiled files that react-native metro has processed

Maksym16:09:28

Aha so lets say a user will paste url to my app, and I create next function:

(defn download [url] (js/require url))
Will it work?

thheller16:09:45

use js/fetch for that

4
thheller16:09:22

or whatever react-native has for network requests. I don't develop react-native apps so I'm not actually sure

Maksym16:09:45

okay thank you, I forgot about fetch

Maksym16:09:41

Another thing which I don't understand is why do I have error when I try to load audio from a URL. I use expo-va and my code is pretty simple:

(ns example.views.notification
  (:require
   ["expo" :as ex]
   ["react-native" :as rn]
   ["expo-file-system" :as fs]
   ["expo-asset" :refer (Asset)]
   ["expo-av" :refer (Audio)]))

(defn test []
(.catch (.then (.createAsync (.-Sound Audio) {:uri ""})(fn [x] (prn "Loaded"))) #(prn % " error")))
When I call (test) I recieve error:
#object[Error Error: Cannot load an AV asset from a null playback source] " error"
I have same code in expo snack and it does work 😕 Please help me 🙏

danielneal17:09:07

Couod it be because the map with uri in need to be a js object

danielneal17:09:34

#js {:uri "..."}

Maksym21:09:45

@danieleneal yeah I was thinking about same issue, I'll try to use #js {:uri "..."} tomorrow, thank you