5

In my project.clj I've defined the dependency

[cljsjs/moment "2.10.6-0"]

and I'm requiring it in my cljs file using

(:require [cljsjs.moment :as m])

I try and use it like this

(m/from-now 3485736776)

But it says Uncaught ReferenceError: cljsjs is not defined

I also tried

(m/fromNow 3485736776)

Just in case the function call was wrong, but I get the same error ... any ideas?

2 Answers 2

7

There's a explanation in cljsjs's wiki page => A Quick JavaScript Interoperability Refresher

basically, require cljsjs's package without :as or :refer. and the library--moment in your case, available in js global namespace. Here is a example from my cljs repl:

(require '[cljsjs.moment])
;;=> nil
(js/moment)
;;=> #object[Moment Sat Oct 24 2015 04:29:19 GMT+0700]
(.fromNow (js/moment) 3485736776)
;;=>"a few seconds"
1
  • Actually the timestamp needs to be passed into the moment constructor so the answer should be (.fromNow (js/moment 3485736776)) ... but yes it is used from the js global namespace, which was what I'd missed. Strange because I'm using cljsjs/d3 with :as and it works great
    – stukennedy
    Oct 24, 2015 at 21:39
2

In (:require [cljsjs.moment :as m]) remove the :as m and that should work. After this the functions in moment will appear under js/.

See https://github.com/cljsjs/packages/wiki/Using-Packages for an example using cljsjs.Showdown.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.