0

I've tried adding a dependency to my deps.edn:

{:deps {cljsjs/js-yaml   {:mvn/version "3.3.1-0"}
       ...}

But I'm not able to call functions from that library.

In the REPL:

cljs.user=> (require '[cljsjs.js-yaml])
cljs.user=> js/safeLoad
Execution error (ReferenceError) at (<cljs repl>:1).
safeLoad is not defined

The instructions I found are for leinigen (project.clj). Do I need to do something special to get it working in deps.edn?

Victor Basso
  • 5,556
  • 5
  • 42
  • 60
  • 1
    You use `(:require ...)` which is just a keyword lookup when used outside the `ns` form. You need `(require '[...])`. Not sure cljsjs can be required at the REPL like this though, but there is no difference in including it via `deps.edn` or `project.clj`. – Thomas Heller Oct 18 '19 at 20:43
  • Oh, thank you, that was a typo. I still get the same output after removing `:`. Question updated. Also, I do get an `#object` when I try another library in the REPL. – Victor Basso Oct 18 '19 at 20:49

1 Answers1

1

You need to do js/jsyaml.safeLoad and at the repl you need to use the function require rather than the symbol used in a ns declaration.

bfabry@18723-bfabry /t/foo> plk
ClojureScript 1.10.520
cljs.user=> (require '[cljsjs.js-yaml])
nil
cljs.user=> (js/jsyaml.safeLoad "app:\n  bar: baz\n")
#js {:app #js {:bar "baz"}}
cljs.user=>

the packages are namespaced using js objects of their own name.

bfabry
  • 1,874
  • 1
  • 13
  • 21