我正在跟踪一个项目的最小示例的影子-cljs快速启动文档。这是链接。
我有一个shadow-cljs.edn文件:
;; shadow-cljs configuration
{:source-paths
["src/dev"
"src/main"
"src/test"]
:dev-http {8080 "public"}
:dependencies
[]
:builds
{:frontend
{:target :browser
:modules {:main {:init-fn acme.frontend.app/init}}
}}}在/Users/pedro/projects/acme-app/src/main/acme/frontend/app.cljs中,我还拥有:
(ns acme.frontend.app)
(defn init []
(println "Hello World"))我可以使用命令构建并查看它:
$ npx shadow-cljs watch frontend
shadow-cljs - config: /Users/pedro/projects/acme-app/shadow-cljs.edn
shadow-cljs - HTTP server available at http://localhost:8080
shadow-cljs - server version: 2.20.2 running at http://localhost:9630
shadow-cljs - nREPL server started on port 61214
shadow-cljs - watching build :frontend
[:frontend] Configuring build.
[:frontend] Compiling ...
[:frontend] Build completed. (127 files, 0 compiled, 0 warnings, 6.97s)因为init函数是一个"Hellow“函数,所以我希望在某个地方看到它。但是,我找不到任何地方“展示”“你好世界”来看它的效果。
“你好世界”应该出现在哪里?是否假定中只有才能作为程序员调用的函数在中可用?
"hello world“没有打印在终端上(见上面检索到的消息),也没有显示在localhost:8080上的UI上(这可能需要在HTML中进行调整--参见下面的图),也不会出现在浏览器控制台上(可能需要js/console.log)。
这些是在执行npx shadow-cljs node-repl之后调用REPL中函数的失败尝试。
cljs.user=> (acme.frontend.app/init)
------ WARNING - :undeclared-var -----------------------------------------------
Resource: <eval>:1:2
Use of undeclared Var acme.frontend.app/init
--------------------------------------------------------------------------------
cljs.user=> (main.acme.frontend.app/init)
------ WARNING - :undeclared-ns ------------------------------------------------
Resource: <eval>:1:2
No such namespace: main.acme.frontend.app, could not locate main/acme/frontend/app.cljs, main/acme/frontend/app.cljc, or JavaScript source providing "main.acme.frontend.app"
--------------------------------------------------------------------------------这是localhost:8080上的图像

发布于 2022-10-04 04:48:03
您似乎跳过了“快速启动”中提到的public/index.html的创建。构建使用的是:target :browser,因此它意味着要在浏览器中加载。HTML会做到这一点。加载时,您将在浏览器控制台中看到println。
对于REPL,如果可以使用,代码总是需要在加载之前加载。因此,在运行(require '[acme.frontend.app :as x])之前需要一个(x/init)。
https://stackoverflow.com/questions/73941197
复制相似问题