Closed macklinhrw closed 2 years ago
Try adding :externs ["datascript/externs.js"]
to :compiler-options
map in shadow-cljs.edn
? #298 #216
Try adding
:externs ["datascript/externs.js"]
to:compiler-options
map inshadow-cljs.edn
? #298 #216
This worked! Thanks, and of course, 1 line of code fixes my 6 hours of headache.
Here is the new config file for anybody interested:
;; shadow-cljs configuration
{:source-paths
["src/clojure/src/main"]
:dependencies
[[datascript "1.3.13"]]
:builds
{:lib
{:target :node-library
:output-to "src/clojure/bundle/clojure.cjs"
:compiler-options {:externs ["datascript/externs.js"]}
:exports-var hello/exports}}}
Great! Added to README too
Hello, I'm having some difficulty with using datascript in my chrome extension.
I'm building from clojurescript with shadow-cljs, using build settings
:target :node-library
and then importing the bundle in my chrome extension.Besides some funkiness with the imports, everything has worked as expected, and I've been able to execute the bundled Clojure code from my chrome extension. I know that datascript has a javascript API, but I'm currently testing out this project setup to see if the added convenience of having a clojure REPL and developing the datascript queries/logic in clojurescript is worth it.
Here is my
shadow-cljs.edn
The problem I'm having, is that my datascript query works perfectly fine when executed from a Clojure REPL, but when I run the code from the chrome extension the results of the query are, as far as I can tell, replaced with nil values.
My
hello.cljs
fileThe result that gets printed when ran from the Clojure repl is
#{[1 Title]}
.But when the function is called from my chrome extension, here is what gets printed:
I think this isn't a datascript problem, and this is related somehow to the specifics of compiling and running my Clojure code in a chrome extension. However, since datascript has a javascript API* that has the expected behavior, I hope there might be some insights into my problem. Thank you!
*I set up this same project using the javascript API and it works as expected.
Here is my javascript code for reference:
Popup.svelte
clojure.ts
The build tool I'm using on the javascript side of things is vite. Github Repo (the code isn't great): https://github.com/macklinhrw/Bookmarks