【问题标题】:lein cljsbuild gives "Could not write JavaScript nil" errorlein cljsbuild 给出“Could not write JavaScript nil”错误
【发布时间】:2018-04-01 19:03:58
【问题描述】:

每次我尝试运行 lein cljsbuild once 时都会出错:

无法编写 JavaScript nil

任何想法或想法都将不胜感激,因为我已经坚持了一段时间,不幸的是不能再进一步了。

这是我一直在做的。

  1. runnin lein new app finance 创建一个名为finance 的新项目
  2. 使用依赖项、cljsbuild、插件和主要规范更新project.clj 文件(见下文)
  3. 运行lein deps,这样就可以了。
  4. 运行lein run 也可以,在控制台中输出“Hello World”。
  5. 尝试运行lein cljsbuild once,然后我得到Could not write JavaScript nil这个错误

    (defproject finance "0.1.0-SNAPSHOT"
            :description "FIXME: write description"
            :plugins [[lein-cljsbuild "1.1.7"]]
            :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.238"]
                           [reagent "0.8.0-alpha2"]]
            :main ^:skip-aot finance.core
            :target-path "target/%s"
            :profiles {:uberjar {:aot :all}}
            :cljsbuild {
                :builds [{
                    :source-paths ["src"]
                    :compiler {
                        :output-to "resources/public/javascripts/dev.js"
                        :output-dir "resources/public/javascripts/cljs-dev"
                        :optimizations :none
                        :pretty-print true}}]})
    

【问题讨论】:

    标签: clojurescript leiningen cljsbuild


    【解决方案1】:

    在新目录中重新开始。您的错误是在创建项目时使用 app 而不是 figwheel

    > lein new figwheel fred
    > cd fred
    > lein cljsbuild once      ; => works fine
    > lein figwheel            ; => starts interactive browser repl
    

    通常您只使用figwheel,但cljsbuild once 也可以。

    您的 project.clj 现在如下所示。请特别注意您缺少的 :plugins 部分:

    (defproject fred "0.1.0-SNAPSHOT"
      :min-lein-version "2.7.1"
      :dependencies [[org.clojure/clojure "1.9.0"]
                     [org.clojure/clojurescript "1.9.946"]
                     [org.clojure/core.async  "0.4.474"]]
    
      :plugins [[lein-figwheel "0.5.15"]
                [lein-cljsbuild "1.1.7" :exclusions [[org.clojure/clojure]]]]
    
      :source-paths ["src"]
      :cljsbuild {:builds
                  [{:id "dev"
                    :source-paths ["src"] 
                    ;; The presence of a :figwheel configuration here will cause figwheel to inject the
                    ;; figwheel client into your build
                    :figwheel {:on-jsload "fred.core/on-js-reload"
                               ;; :open-urls will pop open your application in the default browser once
                               ;; Figwheel has started and compiled your application.  Comment this out
                               ;; once it no longer serves you.
                               :open-urls ["http://localhost:3449/index.html"]}
    
                    :compiler {:main fred.core
                               :asset-path "js/compiled/out"
                               :output-to  "resources/public/js/compiled/fred.js"
                               :output-dir "resources/public/js/compiled/out"
                               :source-map-timestamp true
                               ;; To console.log CLJS data-structures make sure you enable devtools in Chrome
                               ;; https://github.com/binaryage/cljs-devtools
                               :preloads [devtools.preload]}}
                   ;; This next build is a compressed minified build for production. You can build this
                   ;; with: lein cljsbuild once min
                   {:id "min"
                    :source-paths ["src"]
                    :compiler {:output-to "resources/public/js/compiled/fred.js"
                               :main fred.core
                               :optimizations :advanced
                               :pretty-print false}}]}
    
      :profiles {:dev {:dependencies [[binaryage/devtools "0.9.9"]
                                      [figwheel-sidecar "0.5.15"]
                                      [com.cemerick/piggieback "0.2.2"]]
                       ;; need to add dev source path here to get user.clj loaded
                       :source-paths ["src" "dev"]
                       ;; for CIDER
                       ;; :plugins [[cider/cider-nrepl "0.12.0"]]
                       :repl-options {:nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]}
                       ;; need to add the compliled assets to the :clean-targets
                       :clean-targets ^{:protect false} ["resources/public/js/compiled"
                                                         :target-path]}})
    

    【讨论】:

    • 没问题。这周我也一直在努力解决 CLJS 配置问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多