shadow-cljs icon indicating copy to clipboard operation
shadow-cljs copied to clipboard

React native NPM dependencies fail to load obscurely in the REPL if not on the main code path

Open dmg46664 opened this issue 1 year ago • 0 comments

From https://clojurians.slack.com/archives/C6N245JGG/p1659098445064339

So I wanted to experiment with adding NPM lib react-native-logs to my react-native shadow-cljs project, so I :

  • yarn'd it, created a new namespace
  • and added ["react-native-logs" :refer [logger]]

but nothing I did could get logger to appear in the REPL (loading file or namespace) in a way that made sense. This is expected ✅ apparently given the way Metro works. It all worked perfectly if I used it from within the :app main namespace, or even required the new namespace from a linked one.

The stacktrace you do get is

[2022-07-29 13:08:26.165 - WARNING] :shadow.cljs.devtools.server.util/handle-ex - {:msg {:op :cljs-compile, :input {:code "(cljs.core/load-file \"/Users/dmg46664/projects/samson/src/main/dimigi/network.cljs\")", :ns user, :repl true}, :include-init false, :call-id 5, :from 3}}
AssertionError Assert failed: (rc/valid-resource? rc)
	shadow.build.data/add-source (data.clj:220)
	shadow.build.data/add-source (data.clj:220)
	shadow.cljs.repl/repl-ns (repl.clj:325)
	shadow.cljs.repl/repl-ns (repl.clj:319)
	shadow.cljs.repl/process-read-result (repl.clj:504)
	shadow.cljs.repl/process-read-result (repl.clj:484)
	shadow.cljs.repl/process-input (repl.clj:647)
	shadow.cljs.repl/process-input (repl.clj:625)
	shadow.cljs.repl/repl-load-file* (repl.clj:281)
	shadow.cljs.repl/repl-load-file* (repl.clj:259)
	shadow.cljs.repl/repl-load-file (repl.clj:317)
	shadow.cljs.repl/repl-load-file (repl.clj:315)

The issue being reported is cosmetic because it's not obvious to the user why the error is occurring and very unlike a Clojure ™️ REPL experience. If shadow-cljs could hint in this scenarios so others don't suffer the hours it took me :sweat_smile:

Some relevant versions:

thheller/shadow-cljs      {:mvn/version "2.19.8"}
cider/cider-nrepl {:mvn/version "0.28.5"}

    "react": "17.0.2",
    "react-dom": "^17.0.2",
    "react-native": "^0.67.4",

dmg46664 avatar Jul 29 '22 13:07 dmg46664