r0man / cljs-http

A ClojureScript HTTP library.
582 stars 93 forks source link

Uncaught ReferenceError: cljs_http is not defined #129

Open xlisp opened 3 years ago

xlisp commented 3 years ago

I use the cljs-http in chrome extension, it's version "0.1.46" . but i get this error:


(go (let [response (<! (http/get "https://api.github.com/users"
                           {:with-credentials? false
                            :query-params {"since" 135}}))]
        (prn (:status response))
        (prn (map :login (:body response)))))
截屏2021-02-04 上午12 09 44
ulrichschinz commented 2 years ago

Hi there. Could you solve that problem, I get the same error in similar circumstances.

(ns myproject.rap.api
  (:require-macros [cljs.core.async.macros :refer [go]])
  (:require [cljs-http.client :as http]
            [cljs.core.async :refer [<!]]))

(defn get-document [lemmisee]
  (go (let [response (<! (http/get "https://api.github.com/users" 
                                   {:with-credentials? false
                                    :query-params {"since" 135}}))]
        (prn response))))

Opening the repl and calling (get-document 1) leaves me with following message:

myproject.rap.api=> (get-document 1)
#object[TypeError TypeError: Cannot read properties of undefined (reading 'get_document')]
         (<NO_SOURCE_FILE>)

Calling only the http/get request, says me, that cljs_http is not defined:

(<! (http/get "https://api.github.com/users"
                                 {:with-credentials? false
                                  :query-params {"since" 135}}))

#object[ReferenceError ReferenceError: cljs_http is not defined]
         (<NO_SOURCE_FILE>)

I already removed all from ./target/dev and also refreshed cache in ~/.m2/repository. But it leaves me with this error.

Any hints?

ulrichschinz commented 1 year ago

Hi there,

I solved the problem. I just didn't require the new created file, which in turn required the other stuff (like cljs-http). After requiring it in another file, it just worked fine. Given the example above I had to do a

(:require [myproject.rap.api :as api])

Then I could just use it.