This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-05-24
Channels
- # announcements (1)
- # babashka (86)
- # beginners (75)
- # boot-dev (1)
- # cljdoc (18)
- # cljs-dev (1)
- # cljsrn (67)
- # clojure (127)
- # clojure-australia (1)
- # clojure-dev (2)
- # clojure-europe (9)
- # clojure-nl (2)
- # clojure-serbia (2)
- # clojure-spec (11)
- # clojure-uk (14)
- # clojurescript (17)
- # code-reviews (4)
- # conjure (37)
- # core-async (11)
- # datomic (21)
- # emacs (1)
- # helix (36)
- # jobs (6)
- # malli (1)
- # meander (20)
- # re-frame (13)
- # reagent (49)
- # remote-jobs (11)
- # rum (1)
- # sci (1)
- # shadow-cljs (29)
- # sql (17)
- # vim (2)
I’m trying to use react navigation 5 in my Krell RN app, however, I’m having difficulties loading it in my cljs files. On their “Getting started” page, they say that we have to use:
import { NavigationContainer } from '@react-navigation/native';
I’ve tried to replicate this as follows in cljs:
(ns my-app.core (:require ["@react-navigation/native" :refer [NavigationContainer]]))
But NavigationContainer
just ends up being undefined/nil.
If I run
(require '["@react-navigation/native" :refer [NavigationContainer]])
from the REPL, I will get
Unexpected error (IllegalArgumentException) compiling at (REPL:1).
Don't know how to create ISeq from: java.lang.Character
I’ve also tried the following:
(js/require "@react-navigation/native")
But this also returns nil.
Any ideas what I am doing wrong here?
For the installation of react navigation, I have followed their instructions:
npm install @react-navigation/native
npm install react-native-reanimated react-native-gesture-handler react-native-screens react-native-safe-area-context @react-native-community/masked-view
@michael.w.jung did you check if you need to import $default
there's no magic way us to detect that you need to look at the library and see how it's exported
@dnolen You mean like this?
(ns my-app.core (:require ["@react-navigation/native$default" :refer [NavigationContainer]]))
This doesn’t work either. Also, as we import it with curly braces in JS, it shouldn’t be a default export, right?
I don’t know much about these things, though...@michael.w.jung you need to know about 🙂
I’m using this library, with shadow-cljs, and it works. I’m not saying that it’s a krell/shadow-cljs thing. It’s probably something to do with your setup… If you want to see what is available when you require a given library, require it in the REPL:
(require "@your-lib")
If you don’t, then something went wrong upstream.@michael.w.jung also (js/require "@react-navigation/native")
if that doesn't work as you said above then something else is probably wrong
1. Compiling your project will detect Node modules - this gets dumped into a file that Metro does see in the output directory
It seems to be there:
module.exports = {
npmDeps: {
"react-native": require('react-native'),
"react-dom": require('react-dom'),
"@react-navigation/native": require('@react-navigation/native'),
"react": require('react') }
};
did you reload your RN app? new npm dependencies cannot be hot-reloaded or REPL require'd in without being there by the initial load first
you have recompile ClojureScript & reload the entire app if you import something from node_modules
node_modules/@react-navigation/native/lib/module/index.js looks like this:
export * from '@react-navigation/core';
export { default as NavigationContainer } from './NavigationContainer';
...
So no default export if I understand this correctlyYes, I think I reloaded / rebuilt everything.
I threw away the whole target directory and reran clj -M -m krell.main -co build.edn -c
another way to debug is the edit index.js
and console.log
this library that you're trying to use
Ok, I added the following to index.js
import { NavigationContainer } from '@react-navigation/native';
console.log(NavigationContainer);
console.log(typeof(NavigationContainer));
console.log(NavigationContainer === undefined);
The metro output says:
{"$$typeof": Symbol(react.forward_ref), "render": [Function NavigationContainer]}
object
false
So to me this looks like it works in JSnow if you look at the generated JS for that namespace you should see something that looks sensible
there is no such thing as dynamic require in Metro - so we just monkey patch a global JS require
function that will return the library then you invoke it
this is how you can get a handle on modules and assets even though Metro never saw ClojureScript
@michael.w.jung before you go look at though
console logging the npm_deps.js
import in index.js
is probably more useful - it's a JS object that will be used by ClojureScript to "import" those libraries
Very odd. Now the library is no longer in npm_deps.js
...
I deleted the target folder and reran clj -M -m krell.main -co build.edn -c
. Still gone.
your ClojureScript require cannot be in some random file outside of the entry point dep graph
i.e. a.core
is the app entrypoint and you have some side file b.core
which imports Node library
Ok, that’s why it was gone. I commented out some stuff before and it no longer was in that dependency graph. It is back now that I fixed this.
Well, I certainly don’t feel like one 😄
It seems to work now
I have no idea what I changed. It probably really was because I removed the require of the file that imported the lib when I tried to debug the issue.
Thank you very much for your help @dnolen. I was about to give up on this. Much appreciated!
But hopefully the above shows Krell works in a way intentionally to make debugging issues relatively straightforward
Yes, it definitly did. I specifically chose Krell because it seemed rather simple and straightforward. I did some experiments with re-natal and expo in the past, but that was a complete mystery to me. I’m still pretty much a newbie in both CLJS and JS.
I have added another library to my project. This time with a default export. And again, I was having quite some trouble until I finally managed to get it to run.
I think I’m still missing a piece of the picture: When I add a new dependency, which steps do I need to take?
I thought I have to do this:
1. npm add my-lib
2. Require the library in cljs
3. Recompile using clj -M -m krell.main -co build.edn -c
4. Restart the Android app
But I think this wasn’t enough. I also did the following things in some order I don’t remember:
• Delete and rebuild the target
dir
• Restart metro with npx react-native start
• Reinstall the Android app with npx react-native run-android
(I’m not building for iOS at the moment)
Metro also has caching problems - but otherwise I don't think any of those other steps should be necessary
definitely have gotten into funny situations w/ Metro which have nothing to do w/ Krell that requires a whole cycle