This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-01-12
Channels
- # babashka (3)
- # beginners (9)
- # clojure (13)
- # clojure-dev (3)
- # clojure-europe (50)
- # clojure-nl (1)
- # clojure-norway (7)
- # clojure-uk (3)
- # clojurescript (3)
- # core-async (2)
- # dev-tooling (2)
- # honeysql (4)
- # hyperfiddle (2)
- # kaocha (1)
- # lsp (5)
- # off-topic (18)
- # polylith (4)
- # portal (2)
- # shadow-cljs (19)
- # squint (1)
- # vrac (1)
I'm trying to understand how to import an NPM library with CLJS. I'm using https://tauri.app/, which is an electron-like desktop wrapper, but I'm pretty sure this isn't a Tauri-related issue - I get the same problem in a browser. I'm using shadow-cljs and trying to replicate the following code which loads thishttps://github.com/tauri-apps/tauri-plugin-sql/tree/v1 (which is just a JS library):
import Database from "tauri-plugin-sql-api";
const db = await Database.load("sqlite:test.db");
The library exports the database text https://github.com/tauri-apps/tauri-plugin-sql/blob/v1/dist-js/index.d.ts#L20C1-L20C30. So far I've installed the NMP library, and tried something like:
(ns app.core
(:require ["tauri-plugin-sql-api" :refer [Database]]))
(. Database load "sqlite:test.db")
but all I get is
TypeError: undefined is not an object (evaluating 'module$node_modules$tauri_plugin_sql_api$dist_js$index_min.Database.load')
Do I need to build externs for shadow-cljs? Or is that just a clojurescript compiler. I can't seem to get anything to work.There are different kinds of things you have to write in :require
depending on how exactly what you need have been exported.
In this case, try ["..." :default Database]
.
If that doesn't work, consult https://shadow-cljs.github.io/docs/UsersGuide.html#_using_npm_packages
Brilliant, thanks @U2FRKM4TW, that's a handy page. The thing that worked for me was:
["tauri-plugin-sql-api$default" :as Database]