Fork me on GitHub
#clojurescript
<
2022-12-10
>
DerTev20:12:35

Hey! I dont get how to use ClojureScript interop correctly. Ive used npm install pocketbase --save`` to install the PocketBase SDK via NPM + Shadow-Cljs. But when I now try to import and use the PocketBase``-Class with

clojure
(ns writers-corner.utils.pocketbase
  (:require ["pocketbase" :refer [PocketBase]]))

(def client (PocketBase. ""))
I get the error TypeError: module$node_modules$pocketbase$dist$pocketbase_es_mjs.PocketBase is not a constructor`` Any idea how to fix this?

p-himik21:12:05

Two things to try: • Read https://shadow-cljs.github.io/docs/UsersGuide.html#_using_npm_packages and see where you went wrong • Log the value of PocketBase and see whether it makes sense or not

p-himik21:12:06

Maybe there is something else at play (that es_mjs looks suspicious) but I'd still try the above.

DerTev21:12:45

lol, PocketBase is nil

DerTev21:12:56

But I dont get, what I did wrong

p-himik21:12:18

Have you read the linked document? Chances are, that :refer [PocketBase] should actually be :as PocketBase. Alternatively, maybe the whole thing should be ["pocketbase$default" :as PocketBase]. Or maybe it's something else.

DerTev21:12:36

Ah, yes its a default import

DerTev21:12:43

But it says nil anyways

p-himik21:12:24

Well, I've provided all resources I had.

p-himik21:12:52

:as should be the most generic import. Does it result in a nil as well?

DerTev21:12:28

Ah, it worked with

(:require ["pocketbase$default" :as PocketBase])

DerTev21:12:38

Thank you very much!!!

👍 1