1

我试图在我的re-frame/reagent/leiningen项目中使用cljsjs/vis,但是在将此库导入命名空间时出现错误。

cljsjs/vis in namespace required but not available

尝试使用其他库进行图表/数据可视化,但结果仍然相同。将 JS 库导入 clojurescript 项目似乎有问题。

莱宁根project.cljs文件

(defproject test1 "0.1.0-SNAPSHOT"
  :dependencies [[org.clojure/clojure "1.10.1"]
                 [org.clojure/clojurescript "1.10.764"
                  :exclusions [com.google.javascript/closure-compiler-unshaded
                               org.clojure/google-closure-library
                               org.clojure/google-closure-library-third-party]]
                 [thheller/shadow-cljs "2.9.3"]
                 [reagent "0.10.0"]
                 [re-frame "0.12.0"]
                 [cljs-ajax "0.7.5"]
                 [cljsjs/vis "4.21.0-1"]]

  :plugins [[lein-shadow "0.2.0"]

            [lein-shell "0.5.0"]]

  :min-lein-version "2.9.0"

  :source-paths ["src/clj" "src/cljs"]

  :clean-targets ^{:protect false} ["resources/public/js/compiled" "target"]


  :shell {:commands {"open" {:windows ["cmd" "/c" "start"]
                             :macosx  "open"
                             :linux   "xdg-open"}}}

  :shadow-cljs {:nrepl {:port 8777}

                :builds {:app {:target :browser
                               :output-dir "resources/public/js/compiled"
                               :asset-path "/js/compiled"
                               :modules {:app {:init-fn test1.core/init
                                               :preloads [devtools.preload]}}

                               :devtools {:http-root "resources/public"
                                          :http-port 8280
                                          }}}}

  :aliases {"dev"          ["with-profile" "dev" "do"
                            ["shadow" "watch" "app"]]
            "prod"         ["with-profile" "prod" "do"
                            ["shadow" "release" "app"]]
            "build-report" ["with-profile" "prod" "do"
                            ["shadow" "run" "shadow.cljs.build-report" "app" "target/build-report.html"]
                            ["shell" "open" "target/build-report.html"]]
            "karma"        ["with-profile" "prod" "do"
                            ["shadow" "compile" "karma-test"]
                            ["shell" "karma" "start" "--single-run" "--reporters" "junit,dots"]]}

  :profiles
  {:dev
   {:dependencies [[binaryage/devtools "1.0.0"]]
    :source-paths ["dev"]}

   :prod {}

}

  :prep-tasks [])

cljs文件

(ns my-project
  (:require [cljsjs.vis]))
4

1 回答 1

4

shadow-cljs 不支持 CLJSJS 包。相反,您安装那些 CLJSJS 包代表的原始 npm 包并直接使用它。

所以而不是

(ns my-project
  (:require [cljsjs.vis]))

;; accessing vis via js/WhateverGlobalItUses

你做

(ns my-project
  (:require ["vis-network" :as vis]))

;; then use "vis" directly

npm 版本被拆分为多个单独的,因此只需包含您想要使用的任何内容。

shadow-cljs 文档使用npm 包进行了详细说明。还有一个较旧的示例 repo使用vis-network.

于 2020-05-23T22:26:28.747 回答