我有一个项目设置,我想从Clojure服务器中提供服务ClojureScript,并且希望所有内容都在一个存储库中。服务器正常工作,并且返回包括reagent文件在内的静态资源。然而,当处理app.js
时,我看到以下控制台输出
core.cljs?rel=1589815066414:6 undefined
core.cljs?rel=1589815066414:8 Uncaught TypeError: Cannot read property 'call' of undefined
at core.cljs?rel=1589815066414:8
(anonymous) @ core.cljs?rel=1589815066414:8
在我看来,我的代码看起来一切正常。
这是我的core.cljs
(ns ws-poc.core
(:require
[reagent.core :as reagent]))
(.log js/console reagent) ;; <== reagent is undefined, see first line of log
(reagent/render-component
[:h1 Works!]
(. js/document (getElementById "app")))
这是我的index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- <link href="css/style.css" rel="stylesheet" type="text/css"> -->
</head>
<body>
<div id="app">
<h2>Works!</h2>
</div>
<script src="js/compiled/app.js" type="text/javascript"></script>
</body>
</html>
这是我的项目结构
.
├── project.clj
├── resources
│ └── public
│ ├── css
│ ├── index.html
│ └── js
│ └── compiled
│ ├── app.js
│ └── out
│ ├── cljs
│ ├── cljs_deps.js
│ ├── cljsc_opts.edn
│ ├── cljsjs
│ ├── clojure
│ ├── figwheel
│ ├── goog
│ ├── process
│ ├── reagent
│ └── ws_poc
├── src
└── ws_poc
├── core.cljs
└── server
└── core.clj
最后是我的project.clj
(defproject ws-poc "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.8.0"]
[org.clojure/clojurescript "1.10.764"]
[environ "1.2.0"]
[reagent "1.0.0-alpha1"]]
:plugins [[lein-figwheel "0.5.19"]
[lein-cljsbuild "1.1.8"]
[lein-environ "1.2.0"]]
:source-paths ["src"]
:clean-targets ^{:protect false} ["resources/public/js/compiled" "target"]
:main ^:skip-aot ws-poc.server.core
; :target-path "target/%s"
:profiles {:dev {:env {:dev? "true"}
:cljsbuild {:builds
[{:id "dev"
:source-paths ["src"]
:figwheel {}
:compiler {:main ws-poc.core
:asset-path "js/compiled/out"
:output-to "resources/public/js/compiled/app.js"
:output-dir "resources/public/js/compiled/out"
:source-map-timestamp true}}]}}}
:figwheel {:css-dirs ["resources/public/css"]})