How to import npm pacakge from clojurescript?

167 Views Asked by At

Something confuse me when trying use clj command line tools to compile and bundle clojurescript with npm modules.

My clj command :

clj -M --main cljs.main \
    --repl-opts "{:launch-browser false}" \
    --compile hello.core --repl

And my package.json

{
  "dependencies": {
    "@cljs-oss/module-deps": "^1.1.1",
    "react": "^18.2.0",
    "solid-js": "^1.7.5"
  }
}

My demo code

(ns hello.core
    (:require 
        [react :as r] ;; this worked 
        ["solid-js" :as s] ;; this will not work
))


(js/console.log r s) 

When I try to require solid-js, got error : `No such namespace: solid-js, could not locate solid_js.cljs, solid_js.cljc, or JavaScript source providing "solid-js" `.

I notice that, unlike node_modules/react , node_modules/solid-js do not have a index.js in package folder. Is that the reason ? How can I import solid-js correctly ?

I have tried shadow-cljs , when using shadow-cljs the require "solid-js" works well. But I don't understand this. I want use webpack to bundle files ( clojurescript webpack guide ) . Do I MUST use shadow-cljs to compile and bundle apps ?

0

There are 0 best solutions below