crisptrutski / matchbox

Firebase client for Clojure(Script)
Eclipse Public License 1.0
160 stars 20 forks source link

Could not require cljsjs.firebase in file matchbox/registry.cljc #83

Open JimLynchCodes opened 6 years ago

JimLynchCodes commented 6 years ago

I am getting strange errors when I try to use this.

My project.clj:

(defproject joke-generator-firebase "0.1.0-SNAPSHOT" :dependencies [[org.clojure/clojure "1.8.0"] [org.clojure/clojurescript "1.8.51"] [io.nervous/cljs-lambda "0.3.5"] [matchbox "0.0.9"]] :plugins [[lein-npm "0.6.2"] [io.nervous/lein-cljs-lambda "0.6.6"]] :npm {:dependencies [[serverless-cljs-plugin "0.1.2"] ]} :cljs-lambda {:compiler {:inputs ["src"] :options {:output-to "target/joke-generator-firebase/joke_generator_firebase.js" :output-dir "target/joke-generator-firebase" :target :nodejs :language-in :ecmascript5 :optimizations :none}}})

And some code in core.cljs:

(ns joke-generator-firebase.core
  (:require
;    [cljs-lambda.macros :refer-macros [defgateway]]
            [matchbox.core :as m]))

;(defgateway echo [event ctx]
;  {:status  200
;   :headers {:content-type (-> event :headers :content-type)}
;   :body    (event :body)})

(defn okthen [] (println "COOl"))

(def root (m/connect "https://<app>.firebaseio.com"))

(m/auth-anon root)

(m/listen-children
  root [:users :mike :friends]
  (fn [[event-type data]] (prn data)))

(def mikes-friends (m/get-in root [:users :mike :friends]))
(m/reset! mikes-friends [{:name "Kid A"} {:name "Kid B"}])
(m/conj! mikes-friends {:name "Jean"})

(m/deref
  mikes-friends
  (fn [key value]
    (m/reset-in! root [:users :mike :num-friends]
                 (count value))))

(m/unauth)

I run lumo -c $(lein classpath)

Then (load-file "src/joke_generator_firebase/core.cljs")

And it gives me this error:

Could not require cljsjs.firebase in file matchbox/registry.cljc
     (new)
     Function.cljs.core.ex_info.cljs$core$IFn$_invoke$arity$3 (NO_SOURCE_FILE <embedded>:1928:72)
     Function.cljs.analyzer.error.cljs$core$IFn$_invoke$arity$3 (NO_SOURCE_FILE <embedded>:2539:92)
     (NO_SOURCE_FILE <embedded>:5845:320)
     Object.cljs.js.run_async_BANG_ (NO_SOURCE_FILE <embedded>:5823:122)
     Object.cljs.js.process_deps (NO_SOURCE_FILE <embedded>:5823:185)
     Object.cljs.js.process_libs_deps (NO_SOURCE_FILE <embedded>:5825:60)
     (NO_SOURCE_FILE <embedded>:5843:474)
     Object.cljs.js.run_async_BANG_ (NO_SOURCE_FILE <embedded>:5823:122)
     Object.cljs.js.process_deps (NO_SOURCE_FILE <embedded>:5823:185)

Cannot read property 'navigator' of undefined
     (evalmachine.<anonymous>:12:345)
     (evalmachine.<anonymous>:277:278)
     ContextifyScript.Script.runInThisContext (vm.cljs:44:33)
     Object.runInThisContext (vm.cljs:116:38)
     (Object.lt)
     lumo.repl.caching_node_eval (NO_SOURCE_FILE <embedded>:6373:68)
     (NO_SOURCE_FILE <embedded>:5844:410)
     Object.cljs.js.run_async_BANG_ (NO_SOURCE_FILE <embedded>:5823:122)
     Object.cljs.js.process_deps (NO_SOURCE_FILE <embedded>:5823:185)
     Object.cljs.js.process_libs_deps (NO_SOURCE_FILE <embedded>:5825:60)
crisptrutski commented 6 years ago

Him Jim! I'm not very familiar with Lumo - the bulk of the stacktrace seem to refer to its internals and doesn't mean much to me. Taking a guess it seems like the code is trying to use window.navigator, and window is not defined - maybe you'd just need a shim. Firebase's client library has also likely improved environment sniffing and support since the version Matchbox is wrapping.

And I don't think that Matchbox's version is even supported for new database instances.

I suggest trying a recent version directly using [cljsjs/firebase "4.9.0-0"], or a more recent wrapper like https://github.com/degree9/firebase-cljs.

If you appreciate the Matchbox API (it worked well for me!), you're welcome to fork, or become a contributor here. Unfortunately the rot here is bad, and I have zilch spare time or incentive to pull the socks back up :disappointed: